[Tutor] map vs. list comprehension

Jason Massey jason.massey at gmail.com
Tue Feb 14 21:46:53 CET 2006


How about:

>>> [pow(2,x) for x in [1,2,3,4]]

[2, 4, 8, 16]


On 2/14/06, Michael Broe <mbroe at columbus.rr.com> wrote:
>
> I read somewhere that the function 'map' might one day be deprecated
> in favor of list comprehensions.
>
> But I can't see a way to do this in a list comprehension:
>
> >>> map (pow, [2, 2, 2, 2], [1, 2, 3, 4])
> [2, 4, 8, 16]
>
> Is there a way?
>
> Cheers,
> Mike
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060214/c1456e6e/attachment.htm 


More information about the Tutor mailing list