#6-4 Dictionary={ '编译器':'把代码翻译成机器码的程序' , '元组':'不能修改的列表', '列表':'可以储存一组数据的结构,', '汇编器':'将高级语言翻译成汇编码的程序', '字典':'由一系列key和value组成的容器' } for a, b in Dictionary.items(): print(a+'is '+b) #6-5 river={ 'nile':'egypt', 'changjiang':'china', 'huanghe':'zhongguo' } for riv, count in river.items(): print(riv.title()+' is in '+count.title()) #6-8 dog={ 'name':'dog', 'owner':'zi' } cat={ 'name':'cat', 'owner':'wang' } pets=[dog,cat] for sub in pets: for nam, own in sub.items(): print(own.title()+' has a '+ nam.title())
结果:
字典is 由一系列key和value组成的容器
Nile is in Egypt
Changjiang is in China
Huanghe is in Zhongguo
Dog has a Name
Zi has a Owner
Cat has a Name
Wang has a Owner