Loop over dictionary

PHOTO EMBED

Thu Nov 25 2021 16:16:28 GMT+0000 (Coordinated Universal Time)

Saved by @Sourabh #list #forloop #for #loop ##dictionary

# Definition of dictionary
europe = {'spain':'madrid', 'france':'paris', 'germany':'berlin',
          'norway':'oslo', 'italy':'rome', 'poland':'warsaw', 'austria':'vienna' }
          
# Iterate over europe
for key, value in europe.items() :
    print('the capital of ' + str(key) + ' is ' + str(value))
content_copyCOPY

you need the items() method to loop over a dictionary: