map, filter, reduce, zip, range, and.. slice?
George Demmy
gdemmy at layton-graphics.com
Thu Nov 1 19:08:13 CET 2001
Skip Montanaro <skip at pobox.com> writes:
> George> Eddie's solution in the lambda notation...
>
> George> divide = lambda x,s=1: [ x[i:i+s] for i in range(0,len(x),s) ]
> ...
> George> Love them lambdas...
>
> Just out of curiosity, what's the advantage you perceive of lambda over
>
> def divide(x, s=1):
> return [ x[i:i+s] for i in range(0,len(x),s) ]
>
> in this situation?
>
> --
> Skip Montanaro (skip at pobox.com)
> http://www.mojam.com/
> http://www.musi-cal.com/
>
Skip Montanaro writes:
>
> George> Eddie's solution in the lambda notation...
>
> George> divide = lambda x,s=1: [ x[i:i+s] for i in range(0,len(x),s) ]
> ...
> George> Love them lambdas...
>
> Just out of curiosity, what's the advantage you perceive of lambda over
>
> def divide(x, s=1):
> return [ x[i:i+s] for i in range(0,len(x),s) ]
>
> in this situation?
>
> --
> Skip Montanaro (skip at pobox.com)
> http://www.mojam.com/
> http://www.musi-cal.com/
Hi Skip,
There is no "Pythonic" advantage to this representation of which I
know -- I rather suspect there are some serious performance hits with
the lambda form. The orginal poster had mentioned that he was doing a
lot of hacking using nested lambda forms -- he obviously *not*
interested in maximizing Python performance! I just thought it was
interesting to generalize Eddie's "divide" pattern using a lambda form.
Cheers!
G
--
George Demmy
Layton Graphics, Inc
More information about the Python-list
mailing list