[Tutor] replacing range with xrange
bgailer at alum.rpi.edu
Mon Jan 28 23:11:24 CET 2008
Alan Gauld wrote:
>> xrange() is being renamed to range(), so there will be no xrange()
>> range() will return an iterator rather than a list.
> That's sad to see, I use range to generate lists of integers
> almost as much as I use it for iteration. But maybe I'm
> unusual in that respect, I do use Python mainly for
> simulations and its ease of creating large test data
> sets is one of its nicer features. Having to convert
> an iterator into a list is a bit ugly IMHO! I'd have
> preferred to see xrange kept as an iterator and range
> returning a list. That seems to me more in keeping
> with the names too.
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.
919-636-4239 Chapel Hill, NC
More information about the Tutor