使用for循环打印出字典包含的国家,结果只打印了3个国家,为啥,怎么打全?
top3river ={
'nile':'Tanzania',
'nile':'Burundi',
'nile':'Rwanda',
'nile':'Uganda',
'nile':'Sultan',
'nile':'Egypte',
'Amazon River':'Peru',
'Amazon River':'Brazil',
'Yangtze River':'China'
}
for river,country in top3river.items():
print('The ' + river.title() + ' runs through '
+ country.title() + '.')
for name in top3river.keys():
print("The river's name is " + name +'.')
for country in top3river.values():
print(country)
python字典中的key具有唯一性,你的数据字典中只有三个key值,所以后面的{key,value}会覆盖前面的值,所以字典中只有三个国家的
不把你的代码贴出了怎么回答...
代码在哪里?
使用
for in :
的结构遍历