map vs. list-comprehension

Carl Banks invalidemail at aerojockey.com
Wed Jun 29 14:24:07 CEST 2005


F. Petitjean wrote:
> 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.


Notice that zip doesn't do any functional stuff--it merely manipulates
data structures--so it ought not to be lumped in with map, filter, and
reduce.

Fear not, people: just as the BDFL does not indiscriminately add
features, also he does not indiscriminately remove them.  zip, though
it feels a little exotic, is very useful and serves a purpose that no
language feature serves(*), so rest assured it's not going to
disappear.

(*) Excepting izip, of course, which is more useful than zip and
probably should also be a builtin.


-- 
Carl Banks




More information about the Python-list mailing list