google, Python, and eleven (was Re: google and Python ;-)

Peter Hansen peter at engcorp.com
Sun Sep 23 01:23:49 EDT 2001


Andrew Dalke wrote:
> 
> Peter Hansen wrote:
> >>>> def numerology(s):
> >...     f = lambda x, y : x+y
> >...     return reduce(f, map(int, str(reduce(f, map(ord, s)))))
> 
> Instead of making a new lambda function, use operator.add.
> 
>  :)

Thanks. :)  That occurred to me on my walk, an hour later. :(

>>> import operator
>>> f = lambda s: reduce(operator.add, map(int, str(reduce(operator.add, map(ord, s)))))
>>> f('peterhansen')
11

Man!  This numerology stuff is just astounding!  Think of the uses!


-what-do-you-mean-i-still-used-a-lambda-ly yr's,

Peter Hansen



More information about the Python-list mailing list