[Tutor] replacing range with xrange

Alan Gauld alan.gauld at btinternet.com
Tue Jan 29 01:54:10 CET 2008

"bob gailer" <bgailer at alum.rpi.edu> wrote

>> That's sad to see, I use range to generate lists of integers
>> almost as much as I use it for iteration. 

> FWIW on my computer
> l = range(30000000) takes under 0.19 seconds
> l = list(xrange(3000000)) under 0.27.
> So I don't think performance is an issue.

Performance was never an issue for me, its just that I think 
the explicit conversion to list looks ugly. After all a range is 
a range of numbers to my mind and a list (actually a tuple) 
seems like the sensible representation. Making it an iterator 
seems to be based on an assumption that range will 
primarily be used in a for loop.

Alan G

More information about the Tutor mailing list