[Python-ideas] a in x or in y

Ram Rachum ram at rachum.com
Fri Feb 14 00:49:20 CET 2014


That's nice, but having to import a definition like that would be quite
cumbersome.

Also, this doesn't allow lazy evaluation.


On Fri, Feb 14, 2014 at 1:46 AM, Greg Ewing <greg.ewing at canterbury.ac.nz>wrote:

> No language change required:
>
> class either(object):
>
>     def __init__(self, *args):
>         self.args = args
>
>     def __contains__(self, x):
>         for a in self.args:
>             if x in a:
>                 return True
>         return False
>
> pocket = ['hankie', 'pocketknife', 'keys']
> car = ['satchel', 'jacket', 'teddybear']
>
> if 'keys' in either(car, pocket):
>     print("Found them")
> else:
>     print("Lost them")
>
> --
> Greg
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> --
>
> --- You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/python-ideas/LqFVq8sMMwU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140214/ec786a39/attachment.html>


More information about the Python-ideas mailing list