Re: [Tutor] map vs. list comprehension

2006-02-14 Thread Michael Sparks
On Tuesday 14 February 2006 20:57, Michael Broe wrote: ... > 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] >>> [ x**y for x,y in zip([2,2,2,2],[1,2,3,4]) ] [2, 4, 8, 16] To me this is clearer. (despite having written som

Re: [Tutor] map vs. list comprehension

2006-02-14 Thread Danny Yoo
> 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] Hi Michael, If my hands were forcibly tied to avoid map(), I'd

Re: [Tutor] map vs. list comprehension

2006-02-14 Thread Michael Broe
On Feb 14, 2006, at 3:46 PM, Andre Roberge wrote: > [2**i for i in [1, 2, 3, 4]] Ah yes, I'm sorry, I was thinking of the most general case, where the arguments are two arbitrary lists. My example was too specific. Is there a way to do something like the following in a list comprehension?

Re: [Tutor] map vs. list comprehension

2006-02-14 Thread Kent Johnson
Michael Broe 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? The current plan is to

Re: [Tutor] map vs. list comprehension

2006-02-14 Thread Jason Massey
How about: >>> [pow(2,x) for x in [1,2,3,4]] [2, 4, 8, 16] On 2/14/06, Michael Broe <[EMAIL PROTECTED]> wrote: I read somewhere that the function 'map' might one day be deprecatedin favor of list comprehensions.But I can't see a way to do this in a list comprehension: >>> map (pow, [2, 2, 2, 2],

Re: [Tutor] map vs. list comprehension

2006-02-14 Thread Andre Roberge
On 2/14/06, Michael Broe <[EMAIL PROTECTED]> 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] >>> [2**i for i

[Tutor] map vs. list comprehension

2006-02-14 Thread Michael Broe
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 ___