Checking Python containers for an exact value instead of an equal value

191 Views Asked by At

Here's some example code:

>>> l = [ [0], [1], [2] ]
>>> z = [0]
>>> print z == l[0]
True
>>> print z is l[0]
False
>>> print z in l
True

Here's the behavior I'd like to be able to use:

>>> print z in l
False
>>> print l[0] in l
True

I know that I can do something like this, but it doesn't feel Pythonic.

>>> print any([z is i for i in l])
False

I feel like there could be an is in operator or something that I'm missing. What's the best way to handle this situation?

0

There are 0 best solutions below