2013-02-20 228 views

回答

0

使用enumerate

new_lista = [j for i, j in enumerate(lista) if i not in listb] 
+0

非常感謝! – Alwina 2013-02-20 11:59:58

1

您可以嘗試以下。

for x in sorted(listb,reverse=True): lista.pop(x) 

此外,您可能需要確保listb不包含重複索引,並且所有索引號都是有效索引。

for x in sorted(set([y for y in listb if -1 < y < len(lista)]),reverse=True): lista.pop(x) 
相關問題