6-4 词汇表2
python_lists = {
'append': '将元素添加到列表末尾',
'insert': '可在列表的任何位置添加新元素',
'pop': '删除列表末尾的元素',
'remove': '根据值删除元素',
'sort': '对列表进行永久性排序',
'set':'类似于列表,但每个元素都必须是独一无二的',
'values':'返回一个值列表,而不包含任何键',
'keys':'访问字典的键',
'del':'删除指定的键-值对',
'else':'不满足if或elif中的条件测试时,其中的代码就会执行',
}
for word, mean in python_lists.items():
print(word + ":" + mean)
6-5 河流
rivers = {
'nile': 'egypt',
'changjiang': 'china',
'danube': 'germany',
}
for river, country in rivers.items():
print("The " + river.title() + " runs through " + country.title())
for river in rivers.keys():
print(river.title())
for country in rivers.values():
print(country.title())
6-6 调查
favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}
surveys = ['alice', 'bob', 'carmen', 'edward', 'jen']
for person in surveys:
if person in favorite_languages.keys():
print(person.title() + ", thank you for taking the poll.")
else:
print(person.title() + ", please take our poll.")