6-5
rivers = {'nile':'egypt', 'Yangtze river':'china', 'Yellow river':'china'} for river,country in rivers.items(): print('The ' + river + ' runs through ' + country) for river in rivers.keys(): print(river) for country in rivers.values(): print(country)
6-6
fav_las = { 'jen':'py', 'sarah':'c', 'edward':'ruby', 'phil':'py' } for name,language in fav_las.items(): print(name.title() + "'s fav la is " + language.title() + ".") investigate = {'jen', 'phil', 'edward'} for man in fav_las.keys(): if man in investigate: print('thank u.') else: print('welcome')
6-7
info_1 = { 'first_name' : 'Neo', 'last_name' : 'Wang', 'age' : 22, 'city' : 'Yz' } info_2 = { 'first_name' : 'Island', 'last_name' : 'Zheng', 'age' : 22, 'city' : 'Yz' } info_3 = { 'first_name' : 'Island', 'last_name' : 'Wang', 'age' : 1, 'city' : 'Nj' } people = [info_1, info_2, info_3] for info in people: name = info['first_name'] + ' ' + info['last_name'] age = info['age'] city = info['city'] print(name + '\n' + str(age) + '\n' + city + '\n') # for i in info: # print(i + ' ' + str(info[i]))
6-8
island = { 'type':'cat', 'master':'Neo' } niannian = { 'type':'cat', 'master':'Island' } wangcai = { 'type':'dog', 'master':'sarah' } pets = [island, niannian, wangcai] for pet in pets: print('type:' + pet['type'] + '\n' + 'master:' + pet['master'] + '\n')
6-9
fav_places = { 'island':['yz', 'nj', 'aj'], 'neo':['yz', 'nj', 'bj'], 'sarah':['wh'] } for name,place in fav_places.items(): print(name + ':') for i in place: print(i, end=' ') print('\n')
6-10
list = {} list['neo1'] = 1, 2 list['island'] = 6, 7, 8 #print(list) for name,num in list.items(): print('name:' + name + '\n' + 'fav_nums:' + str(num) + '\n')
6-11
标签:info,city,20,name,age,fav,print,Day From: https://www.cnblogs.com/IslandNeo/p/16933600.html