I don't understand the answers for a similar question.
It is clear that this should return True
l = [1,1,1]
reduce(lambda x,y: x== y, l)
However, how do you explain this retuns False (when None==None is True)
l = [None,None,None]
reduce(lambda x,y: x== y, l)
Because
1 == True # 1 == (1 == 1)
is True, but
None == True # None == (None == None)
is False (and None == False is False as well, so once you got False, it stays False).
That's how reduce works: It passes each element and the result of the previous evaluation to the callback. And by that it reduces a sequence of values to one value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With