|
kitty = {'species':'cat',
'owner':'Lucy'}
tide = {'species':'bear',
'owner':'Jim'}
black = {'species':'dog',
'owner':'owen'}
woody = {'species':'bird',
'owner':'Li Lei'}
pets =[kitty,tide,black,woody]
for pet in pets:
for sp ,ow in pet.items():
print ('\nspecies: '+ pet['species'])
print ('owner: '+ pet['owner'])
运行出来:
species: cat
owner: Lucy
species: cat
owner: Lucy
species: bear
owner: Jim
species: bear
owner: Jim
species: dog
owner: owen
species: dog
owner: owen
species: bird
owner: Li Lei
species: bird
owner: Li Lei
问题一:为什么每一个字典都打印了两次?我该怎样修改。
问题二:我想在每一个字典前面打印出列表名,该怎样做
我知道答案
回答被采纳将会获得 10 C币 已有1人回答
|
|