Problem with Python xrange

Diez B. Roggisch deetsNOSPAM at web.de
Sun Jun 6 22:29:56 CEST 2004


Christian Neumann wrote:
 
> x[1:4]  ## It should be return an xrange object with length 3
> Is this really a bug?

No. xrange doesn't create an actual sequence you can slice, instead it
creates an iterable object usable in for ... in ... statements.

The reason is that its much more memory-consuming to create a list if all
you are interested in are only the generated indices.

Use range, if you really want a list.
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list