6-1
man = {'finame' : "a",'laname' : "b",'age' : 11 , 'city' : "c"}
print(man)
6-5
rivers = {
'nile': 'egypt',
'mississippi': 'united states',
'fraser': 'canada',
'kuskokwim': 'alaska',
'yangtze': 'china',
}
for river, country in rivers.items():
print("The " + river.title() + " flows through " + country.title() + ".")
print("\nThe following rivers are included in this data set:")
for river in rivers.keys():
print("- " + river.title())
print("\nThe following countries are included in this data set:")
for country in rivers.values():
print("- " + country.title())
6-10
man = { 'Mary' : [1,2,3] ,'Mike': [4,5,6] }
print (man)
for i,k in man.items():
print(i)
for o in k :
print(" "+str(o))
6-11
cities = {
'santiago': {
'country': 'chile',
'population': 6158080,
'nearby mountains': 'andes',
},
'talkeetna': {
'country': 'alaska',
'population': 876,
'nearby mountains': 'alaska range',
},
'kathmandu': {
'country': 'nepal',
'population': 1003285,
'nearby mountains': 'himilaya',
}
}
for city, city_info in cities.items():
country = city_info['country'].title()
population = city_info['population']
mountains = city_info['nearby mountains'].title()
print("\n" + city.title() + " is in " + country + ".")
print(" It has a population of about " + str(population) + ".")
print(" The " + mountains + " mountains are nearby.")