當遍歷列表中的用戶時,我想打印字典中用戶的名字以表示祝賀,然後重新使用列表打印尚未完成投票的用戶。爲什麼在第一次for循環的用戶之後,列表是否被更改,或者如何重置它,因爲我認爲列表沒有被修改。我可以使這個程序工作的唯一方法是在名爲testusers的程序開始時創建第二個列表。在遍歷phyon中的列表時,列表會被修改(無意)
users = ['jen','seymor', 'patrick', 'tony', 'sarah','edward','billie','mark','jan']
testusers = users
favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
'jan': 'python',
'mark': 'java',
}
print '\nThe following users have taken the poll\n'
for users in favorite_languages.keys():
print('\t'+users.title() + ", thank you for talking the poll.")
print '\nThe following "PERSONS" have not taken the poll.\n'
for ditcher in users:
if ditcher not in favorite_languages.keys():
print "Hey "+ ditcher.title()+ " take the poll!"
爲什麼不使用?請解釋原因 –
@MoinuddinQuadri我希望現在很清楚:) – ettanany
我認爲你應該開始你的回答,比如*「在做......你**重寫**'用戶'...的價值......」*。只要有人開始閱讀答案,他們會在沒有閱讀完整篇文章的情況下得到這個想法:)無論如何,從我這裏+ 1 –