Python list filtering with arguments

One approach is to use lambda:

>>> def foo(a, b, c):
...     return a < b and b < c
... 
>>> myTuple = (1, 2, 3, 4, 5, 6)
>>> filter(lambda x: foo(1, x, 4), myTuple)
(2, 3)

Another is to use partial:

>>> from functools import partial
>>> filter(partial(foo, 1, c=4), myTuple)
(2, 3)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)