map vs. list-comprehension
mandus at gmail.com
Wed Jun 29 13:44:02 CEST 2005
29 Jun 2005 10:04:40 GMT skrev F. Petitjean:
> Le Wed, 29 Jun 2005 09:46:15 +0000 (UTC), Mandus a écrit :
>> Hi there,
>> inspired by a recent thread where the end of reduce/map/lambda in Python was
>> discussed, I looked over some of my maps, and tried to convert them to
>> This one I am not sure how to conver:
>> Given three tuples of length n, b,i and d, I now do:
>> map(lambda bb,ii,dd: bb+ii*dd,b,i,d)
>> which gives a list of length n.
> res = [ bb+ii*dd for bb,ii,dd in zip(b,i,d) ]
aha - thanks! I wasn't aware of zip. Guess I have to put python in a
nutshell on my nightstand (again) :-)
seem to be a tad slower than the map, but nothing serious. Guess it's
the extra zip.
> Hoping that zip will not be deprecated.
Mandus - the only mandus around.
More information about the Python-list