#6.2 favorite_number = { 'alice' : 1, 'bob' : 2, 'frank' : 3, 'harvey' : 4, 'john' : 5, } print(favorite_number) #6.5 river rivers = { 'nile' : 'egypt', 'changjia' : 'china', 'yellow river' : 'china' } for river in rivers : num = rivers.values() print(river + " runs through " + rivers[river]) for river in rivers.keys() : print (river) for river in rivers.values() : print (river) #6.8 pet1 = { 'name' : 'bob', 'belong' : 'Alice' } pet2 = { 'name': 'jam', 'belong': 'frank' } pet3 = { 'name' : 'snoppy', 'belong' : 'harvey' } pets = [pet1,pet2,pet3] for pet in pets: print(pet) #6.10 favorite_numbers = { 'alice' : [1,2,3], 'bob' : [2,3,4], 'frank' : [3,4,5], 'harvey' : [4,8,9], 'john' : [5,6,7] } print(favorite_numbers) #6.11 cities = { 'beijing': { 'country' : 'china', 'population' : '1200k', 'fact' : 'capital' }, 'shanghai' : { 'country' : 'china', 'population': '1300k', 'fact' : 'middle of china' } } for cityname,cityfact in cities.items(): print('\ncityname:' + cityname) country = cityfact['country'] population = cityfact['population'] fact = cityfact['fact'] print('\tcountry: ' + country) print('\tpopulation:' + population) print('\tfact:' + fact)