Is it possible to pass the "__ contains __" function in a list more than one parameter? I'd like to check if at least one of the items i have in a list exist in a different list.
For example: [0,1,4,8,87,6,4,7,5,'a','f','er','fa','vz']
I'd like to check if the one of the items (8,5,'f') are on that list.
How can I do it?
AFAIK, __contains__ takes only one argument and it can't be changed.
However you can do following to get the desired result :
>>> a = [0,1,4,8,87,6,4,7,5,'a','f','er','fa','vz']
>>> any(map(lambda x: x in a, (8,5,'f')))
True
or
>>> from functools import partial
>>> from operator import contains
>>> f = partial(contains, a)
>>> any(map(f, (2,3)))
False
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