问题描述
如何从列表中删除在另一个列表中具有相应索引的所有元素?
a = [1,13,15,16,22,70,3]
index_list = [3,6]
因此最终列表应如下所示:
a = [1,70] # because we removed the elements that have their index equal to 3 and 6.
我尝试过此操作,但是由于删除导致列表的长度被修改,因此会破坏适当的删除:
i = 0
while i < len(a):
del a[index_list[i]]
i +=1
if (i < len(a)-1):
index_list[i+1] = index_list[i+1] - 1
我遇到一个错误。
我该如何进行这项工作?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)