6-1
person = {'first_name':'gu','last_name':'kx','age':'20','city':'tianjin'} print(person)
{'city': 'tianjin', 'first_name': 'gu', 'last_name': 'kx', 'age': '20'} ------------------ (program exited with code: 0)
6-5
rivers = { 'nile': 'egypt', 'amazon': 'brazil', 'changjiang': 'china' } for key, value in rivers.items(): print('The ' + key.title() + ' runs through ' + value.title() + '.') for key in rivers.keys(): print(key.title()) for value in rivers.values(): print(value.title())
The Amazon runs through Brazil. The Changjiang runs through China. The Nile runs through Egypt. Amazon Changjiang Nile Brazil China Egypt ------------------ (program exited with code: 0) Press return to continue
6-8
cat = {'name':'kitty','owner':'lucy'} dog = {'name':'Da Huang','owner':'nancy'} rabbit = {'name':'little white','owner':'mary'} pets = [cat,dog,rabbit] for pet in pets: for key ,value in pet.items(): print('%s:%s'%(key,value.title()))
owner:Lucy name:Kitty owner:Nancy name:Da Huang owner:Mary name:Little White ------------------ (program exited with code: 0) Press return to continue