Iterate over dictionaries in Python


Iterate over dictionaries in Python

#create a dict
mydict = {'jason':5,
'terry':1,
'michael':3,
'sam':6}
#using for loops
for key, value in mydict.items():
print (key, 'corresponds to', value)
terry corresponds to 1

jason corresponds to 5
michael corresponds to 3
sam corresponds to 6


Ace your next data science interview

Get better at data science interviews by solving a few questions per week



Find a bug? Submit a suggested change on Github, or message me on Twitter.