[Python-ideas] a in x or in y

Ethan Furman ethan at stoneleaf.us
Fri Feb 14 01:34:12 CET 2014


On 02/13/2014 03:49 PM, Ram Rachum wrote:
> On Fri, Feb 14, 2014 at 1:46 AM, Greg Ewing wrote:
>>
>> 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
>
> That's nice, but having to import a definition like that would be quite cumbersome.

What?  Importing is cumbersome?  Since when?


> Also, this doesn't allow lazy evaluation.

Certainly it does.  If the target is in the first thing it returns True at that point.

--
~Ethan~


More information about the Python-ideas mailing list