Re: efficiency of range() and xrange() in for loops
- From: "Todd" <goldfita@xxxxxxxxxxxxxxx>
- Date: 5 Apr 2006 13:54:16 -0700
Steve R. Hastings wrote:
When you compile the expression
for i in range(1000):
pass
does Python make an iterator for range(), and then generate the values
on the fly? Or does Python actually allocate the list [0, 1, 2, ..., 999]
and then step through it?
I ran an experiment on this a while back. I thought it generated a
list. But the results turned out to be surprising. Take this with a
grain of salt. I'm not completely sure I did what I meant to do. But
it looks like however you do it, it works out about the same.
http://www.signalsguru.net/articles/pyloops/pyloops.html
.
- Follow-Ups:
- Re: efficiency of range() and xrange() in for loops
- From: mensanator@xxxxxxx
- Re: efficiency of range() and xrange() in for loops
- References:
- efficiency of range() and xrange() in for loops
- From: Steve R. Hastings
- efficiency of range() and xrange() in for loops
- Prev by Date: Re: Filters like old skool Jive, Fudd, Valspeak... Text transformation in Python
- Next by Date: Re: Filters like old skool Jive, Fudd, Valspeak... Text transformation in Python
- Previous by thread: Re: efficiency of range() and xrange() in for loops
- Next by thread: Re: efficiency of range() and xrange() in for loops
- Index(es):
Relevant Pages
|