How many is "too many" with lists?
Courageous
jkraska1 at san.rr.com
Tue May 2 23:42:41 EDT 2000
Neel Krishnaswami wrote:
>
> Courageous <jkraska1 at san.rr.com> wrote:
> >
> > Well, this is a bit off the subject, but in recent Python
> > misadventures, I'm pretty sure that
> >
> > for i in range ( 1000000 ):
> >
> > definitely isn't the right way to loop............
>
> You can use xrange(), which doesn't allocate a whole list, but instead
> returns an object with __getitem__ methods that return the right
> integers to emulate a range. When you need to loop over 10 million
> elements it becomes helpful. :)
Thanks! I was writing:
x = 1000000
while x > 0
dosomething()
x = x - 1
That seemed overbearing. So you're saying that
for x in xrange ( 1000000 )
dosomething()
is equally unexpensive?
C/
More information about the Python-list
mailing list