favorite_nums = {
'Yamato': 23,
"Fubuki": 35,
"Sakura": 10086,
"Shimakaze": 2333,
"Saratoga": 666
}
for name, numin favorite_nums.items():
print(name + "'s favorite number is " + str(num))
6-3 词汇表
vocabulary_table = {
'python': "A popular programing language",
'list': "A kind of structure which linked data with index",
'ergodic': "Travel all stored values in a structure in order",
'tuple': "A kind of structure like a unmodified list",
'output': "an amount of something produced by a person, machine, factory, country, etc"
}
print("python:\t" + vocabulary_table['python'])
print("list:\t" + vocabulary_table['list'])
print("ergodic:\t" + vocabulary_table['ergodic'])
print("tuple:\t" + vocabulary_table['tuple'])
print("output:\t" + vocabulary_table['output'])
6-4 词汇表2
vocabulary_table = {
'python': "A popular programing language",
'list': "A kind of structure which linked data with index",
'ergodic': "Travel all stored values in a structure in order",
'tuple': "A kind of structure like a unmodified list",
'output': "an amount of something produced by a person, machine, factory, country, etc"
}
for vocabulary, explanation in vocabulary_table.items():
print(vocabulary + ":\t" + explanation)
6-5 河流
dict_river = {
'nile': 'Egypt',
'amazon': 'Colombia',
'changjiang': 'China'
}
for river, country in dict_river.items():
print("The " + river + " river runs through " + country)
for river in dict_river.keys():
print(river)
for country in dict_river.values():
print(country)
6-6 调查
research_list = ["Zhang San", "Li Si", "Wang Wu", "Zhou Liu"]
research_result = {
"Zhang San": 13,
"Wang Wu": 25,
"Zhou Liu": 33
}
fornamein research_list:
ifnamein research_result.keys():
print(name + ", thank you for joining our research.")
else:
print(name + ", would you like to join our research?")
cities = {
'Shanghai': {
'country': 'China',
'population': 2.420e7,
'fact': 'Shanghai is a big city'
},
'New York': {
'country': 'USA',
'population': 8.51e6,
'fact': 'New York belongs to USA'
},
'Beijing':{
'country': 'China',
'population': 2.173e7,
'fact': "Beijing is the capital of China"
}
}
for city, info in cities.items():
print(city)
print('Country:\t' + info['country'])
print('Population:\t' + str(info['population']))
print('Describe:\t' + info['fact'])
print()