[Numpy-discussion] Working with lists

Paul Rudin paul at rudin.co.uk
Thu Aug 9 13:14:41 EDT 2007


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

> 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

itertools.izip is faster yet on mine.




More information about the NumPy-Discussion mailing list