?6-1
people = {'first_name': 'john', 'last_name': 'james', 'age': '22', 'city': 'boston'}
print(people['first_name'])
print(people['last_name'])
print(people['age'])
print(people['city'])
6-2
friend_number = {
'day': '1',
'zyf': '7',
'wzy': '22',
'lxd': '0'
}
print(f"day favorite num is {friend_number['day']}.")
print(f"zyf favorite num is {friend_number['zyf']}.")
print(f"wzy favorite num is {friend_number['wzy']}.")
print(f"lxd favorite num is {friend_number['lxd']}.")
6-3
language = {
'Keyword': '编程语言中 具有特殊意义的词。',
'object': 'Python中具有3个属性的数据值——唯一标识,数据类型和值。',
'Str(string)': '字符串的数据类型。',
'Int': '整数的数据类型。'
}
for
print(f"Keyword:{language['Keyword']}.")
print(f"object:{language['object']}.")
print(f"Str(string):{language['Str(string)']}.")
print(f"Int:{language['Int']}.")
?6-4
language = {
'Keyword': '编程语言中 具有特殊意义的词。',
'object': 'Python中具有3个属性的数据值——唯一标识,数据类型和值。',
'Str(string)': '字符串的数据类型。',
'Int': '整数的数据类型。'
}
for program, meaning in language.items():
print(f"{program}:{meaning}")
6-5
river_country = {
'nile': 'egypt',
'Yangtze River': 'china',
'don': 'russia',
'danube': 'france'
}
for river, country in river_country.items():
print(f"The {river} through {country}")
for river in river_country.keys():
print(river)
for country in river_country.values():
print(country)
6-6
favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}
names = ['jen', 'day', 'wzy', 'edward', 'zyf', 'phil']
for name in names:
if name in favorite_languages.keys():
print(f"{name},thank you for talking the poll!")
else:
print(f"{name},please talk your poll!")
?
6-7
people1 = {'first_name': 'john',
'last_name': 'james',
'age': '22',
'city': 'boston'
}
people2 = {'first_name': 'harden',
'last_name': 'kevin',
'age': '26',
'city': 'new york'
}
people3 = {'first_name': 'curry',
'last_name': 'payton',
'age': '32',
'city': 'xian'
}
people = [people1, people2, people3]
for person in people:
name = person['first_name']+ " "+ person['last_name']
print(f"{name},living in {person['city']},is {person['age']} years old.")
6-8
pet_1 = {'type': 'cat',
'owner': "john",
}
pet_2 = {'type': 'dog',
'owner': "james",
}
pet_3 = {'type': 'bird',
'owner': "harden",
}
pets = [pet_1, pet_2, pet_3]
for this in pets:
print(f"{this['type']} belong {this['owner']}.")
6-9
favorite_places = {
'day': ['xian', 'beijing', 'shanghai'],
'lxd': ['tianjin', 'tokyo'],
'zcy': ['new york', 'boston'],
}
for name,places in favorite_places.items():
print(f"{name} love:")
for place in places:
print(place)
6-10
friend_number = {
'day': ['1', '2', '5'],
'zyf': ['7'],
'wzy': ['22', '10', '15'],
'lxd': ['0', '11']
}
for name,nums in friend_number.items():
print(f"\n{name}:")
for num in nums:
print(f"\t{num}")
6-11
cities = {
'beijing': {'country': 'china', 'people': '21_000_000', 'about': 'imperial palace'},
'new york': {'country': 'america', 'people':'16_000_000', 'about': 'central park'},
'paris': {'country':'france', 'people': '15_000_000', 'about': 'Eiffel Tower'}
}
for city_name, city_about in cities.items():
print(f"\n{city_name}:")
print(f"\tcountry : {city_about['country']}")
print(f"\tpeople :{city_about['people']}")
print(f"\thave {city_about['about']}")
|