If I have a function matchCondition(x), how can I remove the first n items in a Python list that match that condition?
matchCondition(x)
n
One solution is to itera
One way using itertools.filterfalse and 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)
Then list(output), gives you:
list(output)
[10, 9, 8, 4, 7]