[Python-Dev] Re: comprehension abbreviation (was: Adding any() andall()) (original) (raw)
Alex Martelli aleaxit at yahoo.com
Wed Mar 30 08:45:10 CEST 2005
- Previous message: [Python-Dev] Re: comprehension abbreviation (was: Adding any() andall())
- Next message: [Python-Dev] itertools.walk()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mar 29, 2005, at 17:41, Terry Reedy wrote: ...
"Steve Holden" <steve at holdenweb.com> wrote in message news:d2asg9$3tf$1 at sea.gmane.org...
Having to write
[x for x in seq] to produce a copy of a list doesn't seem that outrageous to me, Except for (currently) leaving the last value of sequence bound to 'x' after making the copy, how is the above different from list(seq)?
Well, it's less concise, and over an order of magnitude slower:
Nimue:/pypy alex$ python2.4 -mtimeit -s'seq=range(1000)' '[x for x in
seq]'
1000 loops, best of 3: 312 usec per loop
Nimue:/pypy alex$ python2.4 -mtimeit -s'seq=range(1000)' 'list(seq)'
10000 loops, best of 3: 24.3 usec per loop
I fail to see any advantages to compensate for these minuses.
Alex
- Previous message: [Python-Dev] Re: comprehension abbreviation (was: Adding any() andall())
- Next message: [Python-Dev] itertools.walk()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]