is it possible to use the python keyword in
in a filter? I know that binary, unary, assignment operations are equivalent to a function call.
such as
''!=3
is the same as
''.__ne__(3)
is there an analogous thing for the in
function?
I want to do something like this. ..
filter( list1.__in__, list2 )
I guess this can be accomplished with writing the in function... but i just want to know if it is already built in or not.
filter( list1.__contains__, list2 )
is more cleanly written as:
[ v for v in list2 if v in list1 ]
and to show equivalence:
>>> list1 = [2, 4, 6, 8, 10]
>>> list2 = [1, 2, 3, 4, 5]
>>> [ v for v in list2 if v in list1 ]
[2, 4]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With