[Python-ideas] a in x or in y

Ethan Furman ethan at stoneleaf.us
Fri Feb 14 15:50:25 CET 2014


On 02/14/2014 04:15 AM, Steven D'Aprano wrote:
> On Thu, Feb 13, 2014 at 04:34:12PM -0800, Ethan Furman wrote:
>> 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
> [...]
>>> Also, this doesn't allow lazy evaluation.
>>
>> Certainly it does.  If the target is in the first thing it returns True at
>> that point.
>
> No, Ram is correct. either() short circuits the `x in a` tests, but it
> evaluates the individual args eagerly, not lazily.

Ah, thanks.  Ram, my apologies.

--
~Ethan~


More information about the Python-ideas mailing list