更新时间:2023-02-13 21:15:52
使用 和 itertools.count :
itertools.count
from itertools import count, filterfalse data = [1, 10, 2, 9, 3, 8, 4, 7] output = filterfalse(lambda L, c=count(): L < 5 and next(c) < 3, data)
然后list(output),给您:
list(output)
[10, 9, 8, 4, 7]
从python 2.7中的列表中删除每个第n个元素
删除与Python列表中的条件匹配的前N个项目
如何在有条件的情况下使用RemoveAll删除列表中的多个项目?