[Python-ideas] is in operator

Mathias Panzenböck grosser.meister.morti at gmx.net
Wed Sep 26 23:08:29 CEST 2007


Sometimes I want to compare a "pointer" to more then one others. The "in" operator
would be handy, but it uses the "==" operator instead of the "is" operator. So a "is
in" operator would be nice. Though I don't know how easy it is for a newbie to see
what does what.

# This:
if x is in (a, b, c):
	...

# would be equivalent to this:
if x is a or x is b or x is c:
	...

# And of course there should be a "is not in" operator, too:
if x is not in (a, b, c):
	...

# this would be equivalent to tis:
if x is not a and x is not b and x is not c:
	...


Hmmm, maybe a way to apply some kind of comparison between a value and more other
values would be better. But that already exists, so screw this msg:

if any(x is y for y in (a, b, c)):
	...

if all(x is not y for y in (a, b, c)):
	...



More information about the Python-ideas mailing list