【发布时间】:2014-04-30 18:56:01
【问题描述】:
一个不太难的问题,我希望来自 Python 初学者。
我有一个主列表 listA,我需要根据索引列表 listB 中的值将该列表中的项目清零。
因此,例如,给定:
listA = [10, 12, 3, 8, 9, 17, 3, 7, 2, 8]
listB = [1, 4, 8, 9]
我想要的输出是
listC = [10, 0, 3, 8, 0, 17, 3, 7, 0, 0]
这个问题 [1] 看起来很相似,但要求将元素删除,而不是更改。我不确定是否需要类似的方法,但如果需要,我不知道如何应用它。
[1]how to remove elements from one list if other list contain the indexes of the elements to be removed
【问题讨论】: