map vs. list-comprehension

F. Petitjean littlejohn.75 at news.free.fr
Wed Jun 29 06:04:40 EDT 2005


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
> list-comprehensions.
>
> 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) ]

Hoping that zip will not be deprecated.



More information about the Python-list mailing list