1
我是Stack Overflow和Python的新手。 我想通過索引替換列表中的項目,並且當我運行此代碼時只有第一個實例是替換。Python zip()函數不起作用
word = "DRIPPING"
letter = "P"
checkList = [" _ "] * len(word)
letterLocation=[3,4]
for (index, replacement) in zip(letterLocation, letter):
checkList[index] = replacement
print(checkList)
返回[' _ ', ' _ ', ' _ ', 'P', ' _ ', ' _ ', ' _ ', ' _ ']
任何幫助將是非常歡迎的。
'zip'工作得很好,但是你使用'zip',你不應該使用'zip'。 –