[Numpy-discussion] Working with lists

Keith Goodman kwgoodman@gmail....
Thu Aug 9 11:28:42 CDT 2007


On 8/9/07, Gary Ruben <gruben@bigpond.net.au> wrote:
> FWIW,
> The list comprehension is faster than using map()
>
> In [7]: %timeit map(lambda x:x[0],bounds)
> 10000 loops, best of 3: 49.6 -¦s per loop
>
> In [8]: %timeit [x[0] for x in bounds]
> 10000 loops, best of 3: 20.8 -¦s per loop

zip is even faster on my computer:

>> timeit map(lambda x:x[0], bounds)
100000 loops, best of 3: 5.48 µs per loop
>> timeit [x[0] for x in bounds]
100000 loops, best of 3: 2.69 µs per loop
>> timeit a, b = zip(*bounds)
100000 loops, best of 3: 2.57 µs per loop


More information about the Numpy-discussion mailing list