Python——字典操作

一、取出字典中所有的key-value

student={'name':'xiaoming','age':11,'school':'tsinghua'}
for key,value in student.items():
print(key+':'+str(value))

二、取出字典中所有的keys

people={'lifei':'apple','fanming':'peach','gaolan':'banana','hanmeimie':'peach'}
for name in people.keys():
print(name)

**如果想输出按照顺序需要   sorted(people.keys())

三、取出字典中所有的value

people={'lifei':'apple','fanming':'peach','gaolan':'banana','hanmeimie':'peach'}
for fruit in people.values():
print(fruit)
上一篇:Solr后台管理


下一篇:Java学习点滴——泛型