What is xrange?
ethan at stoneleaf.us
Sun Jul 31 08:42:50 CEST 2011
Dennis Lee Bieber wrote:
> On Sat, 30 Jul 2011 21:36:41 +1000, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> declaimed the following in
>> Probably because nobody thought about it, but if it had been proposed to
>> change xrange into an iterator, I'm pretty confident that the suggestion
>> would have been rejected. xrange objects might be lazily generated, but
>> they're also sequence types: you can get their length, and you can index
>> them. (However you can't slice them.) Iterators are not sequence types:
>> they aren't indexable and you can't get their length.
> Ah, but what did they change range() into -- I seem to recall
> reading the Python 3.x turned the regular range() into something else...
> (from Python <3.x returning a full list)
From the What's New docs, in the Views And Iterators Instead Of Lists
range() now behaves like xrange() used to behave, except it works with
values of arbitrary size. The latter no longer exists.
More information about the Python-list