Looping through dictionaries : Dictionary Loop « Dictionary « Python






Looping through dictionaries

Looping through dictionaries
 

#the key and corresponding value can be retrieved at the same time using the 
#iteritems() method.

knights = {'Key 1': 'value 1', 'key 2': 'value 2'}
for k, v in knights.iteritems():
     print k, v



           
         
  








Related examples in the same category

1.for each loop with dictionary
2.Dictionary for loopDictionary for loop