"Mick Krippendorf" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
Fahri Basegmez wrote:
reduce(lambda x, y: x or y, lst)
This doesn't solve the OPs problem since
reduce(lambda x, y: x or y, [False, None])
returns None instead of False.
Mick.
You are right.
I tested None or False and it worked. I assumed order did not matter for or operator.
None or False returns False False or None returns None
You know what they say about assumptions. Live and learn.
Fahri
Hi Fahri,
I don't have a reference at hand, but you might want to check the docs' index or do a google for short circuit python or something similar.
or works by evaluating the first value and returning it if it evaluates to True. Otherwise it returns the second.
>>> 0 or 42
42
>>>
Likewsie, and returns the first if it evaluates to False, otherwise it returns the second.
>>> [] and 42
[]
>>>
The idea is that the evaluation breaks out as soon as it has seen enough to determine the result. Hence, short circuit. And, instead of returning a Boolean, it returns the actual object flanking the operator. Hence, the behaviour observed.
HTH,
Brian vdB
-- http://mail.python.org/mailman/listinfo/python-list