pythonreference.com
search statements, functions, methods, exceptions*
show categories
'for' with a dict
iterate over each key in a dict
myd = {'a': 1, 'b': 2}
for mykey in myd:
print(mykey)
dict -> for each str/int key:
execute block with key
|
as Python iterates over each key in the dictionary, it assigns the key to the loop variable (in the example, mykey), then executes the block. The assignment and block execution happen once for each key in the dict.