Iterating over dictionaries using for loops in Python (or) for loop with key and value in python

key is just a variable name.
for key in d: will simply loop over the keys in the dictionary, rather than the keys and values. To loop over both key and value you can use the following:
for key, value in d.iteritems():

No comments:

Post a Comment