On 9/26/07, Mathias Panzenböck <grosser.meister.morti@gmx.net> wrote:
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)):


Or in a more obfuscated way:

import operator as op
from itertools import imap
from functools import partial

if any(imap(partial(op.is_,x), (a, b, c))):
        ...

if all(imap(partial(op.is_not,x), (a, b, c))):
     ...


George