6-5 河流
rivers = {
'Yangtze River': 'China',
'Nile': 'Egypt',
'Amazonian River': 'Brazil',
}
for r, c in rivers.items():
print('The ' + r + ' runs through ' + c + '.')
for r in rivers.keys():
print(r)
for c in rivers.values():
print(c)
6-8 宠物
Dabao = {'name': 'Dabao', 'type': 'pekingese', 'master': 'Tom'}
Xiaobao = {'name': 'Xiaobao', 'type': 'husky', 'master': 'Jim'}
Xiaoming = {'name': 'Xiaoming', 'type': 'poodle', 'master': 'Sam'}
pets = [Dabao, Xiaobao, Xiaoming]
for pet in pets:
print('\nName is ' + pet['name'])
print('Type is ' + pet['type'])
print('Master is ' + pet['master'])
6-11 城市
cities = {
'Beijing': {
'country': 'China',
'population': '21 million',
'fact': 'The capital of China',
},
'Washington': {
'country': 'the USA',
'population': '681 thousand',
'fact': 'The capital of the USA'
},
'Moscow': {
'country': 'Russia',
'population': '14 million',
'fact': 'The capital of Russia'
},
}
for city_name, city_info in cities.items():
print('\nCityname: ' + city_name)
print('Population: ' + city_info['population'])
print('Fact: ' + city_info['fact'])