string goes away

Dan Christensen jdc at uwo.ca
Thu Mar 31 22:43:44 EST 2005


"Delaney, Timothy C (Timothy)" <tdelaney at avaya.com> writes:

> Andreas Beyer wrote:
>
>> Yeeh, I was expecting something like that. The only reason to use
>> map() at all is for improving the performance.
>> That is lost when using list comprehensions (as far as I know). So,
>> this is *no* option for larger jobs.
>
> Try it and see. You'll probably be pleasantly surprised.

In fact, in my test, the list comprehension won:

$ /usr/lib/python2.4/timeit.py -s "import string; slist=['aB'*100 for i in range(100)]" "map(string.upper, slist)"

1000 loops, best of 3: 522 usec per loop

$ /usr/lib/python2.4/timeit.py -s "slist=['aB'*100 for i in range(100)]" "[s.upper() for s in slist]"

1000 loops, best of 3: 461 usec per loop

Dan



More information about the Python-list mailing list