[Numpy-discussion] Working with lists

Paul Rudin paul@rudin.co...
Thu Aug 9 12:14:41 CDT 2007


"Keith Goodman" <kwgoodman@gmail.com> writes:

> 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

itertools.izip is faster yet on mine.



More information about the Numpy-discussion mailing list