places = {
'first_choice': 'bali',
'second_choice': 'paris',
}
for choice, place in places.items():
print(choice + " is " + place)
print(choice + " is " + place)
如上面的代码所示,我应该得到以下结果:
second_choice is paris
first_choice is bali
但我得到以下结果:
second_choice is paris
second_choice is paris
first_choice is bali
first_choice is bali
我可以知道我的代码出了什么问题吗?
答案 0 :(得分:0)
在for
循环中,您print
选择两次,这就是重复结果的原因。只使用一个print
可以解决您的问题。