6-1
friend = {'fist_name':'John','last_name':'Steve','age':15,'city':'Guangzhou'}
print(friend)
6-5
rivers = {
'nile':'egypt',
'Changjiang_River':'China',
'Rhine River':'Germany'
}
for river,country in rivers.items():
print('The ' + river + ' runs though ' + country + ' .')
for river in rivers.keys():
print(river)
for country in rivers.values():
print(country)
6-6
participants = ['jen','sarah','jonh','kobe']
for participant in participants:
if participant in favourite_language.keys():
print(participant + ' ,thank you for participating in the survey!')
else:
print(participant + ' , please take part in our survey.')
6-7
friend_1 = {'fist_name':'John','last_name':'Steve','age':15,'city':'Guangzhou'}
friend_2 = {'fist_name':'Kobe','last_name':'bryant','age':38,'city':'Los Angel'}
friend_3 = {'first_name':'Steve','last_name':'Curry','age':30,'city':'San Francisco'}
people = [friend_1,friend_2,friend_3]
for friend in people:
print(friend)
6-9
favourite_places = {
'Kobe': ['Beijing','Shanghai','Guangzhou'],
'Steve': ['Mexico','Australia','Canada'],
'Green': ['England','France','Japan']
}
for name,places in favourite_places.items():
print(name + ' \'s favourite_places are: ')
for place in places:
print(place)