且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除与Python列表中的条件匹配的前N个项目

更新时间:2023-02-13 21:15:52

使用 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),给您:

[10, 9, 8, 4, 7]