[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LFM + LFSP = LFE?



Michael Vanier wrote:
> 
> all_same = reduce(lambda x, y:
>                       if x == y:
>                           return 1
>                       else:
>                           return 0,
>                   [1, 1, 1, 1, 1])
> 
> At least, it didn't the last time I checked ;-)

I think you misremember.

 >>> all_same = reduce(lambda x, y:
...     x==y,
...     [1,1,1,1,1,1])
 >>> all_same
1
 >>> all_same = reduce(lambda x, y:
...     x==y,
...     [1,1,1,1,0,1])
 >>>
 >>> all_same
0

Python's lambda is well-known to be less powerful than its named 
functions but that has nothing to do with indentation. Python knows the 
statement isn't done because it hasn't seen the end-paren so it ignores 
newlines.

  Paul Prescod