So this is some code I did working exercise 6-9 of Chapter 6 in Python Crash Course book.
favorite_places = {
'joe': {
'paris': 'france',
'hamburg': 'germany',
'cairo': 'egypt',
},
'anna': {
'tripoli': 'libya',
'tokyo': 'japan',
'moskva': 'russia',
},
'henry': {
'sydney': 'australia',
'quebec': 'canada',
'rio de janeiro': 'brazil',
}
}
for person, places in favorite_places.items():
print(person.title() + "'s favorite places are: ")
places = places.items()
for place in places:
print(place[0].title() + " in " + place[1].title() + ".")
print("\n")
Then the output is like this:
Joe's favorite places are:
Cairo in Egypt.
Hamburg in Germany.
Paris in France.
Is there a way to just get the key-value from the places variable and print it the same way I did but without converting places to a list? I think it's a bit messy like this...