[Numpy-discussion] Working with lists

Keith Goodman kwgoodman at gmail.com
Thu Aug 9 12:28:42 EDT 2007


On 8/9/07, Gary Ruben <gruben at 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