Problem with Python xrange
r holland
rhh at structurelabs.com
Sun Jun 6 18:55:56 EDT 2004
xrange is a special object intended for operations like looping
try this:
a=xrange(10)
b=range(10)
if you do:
type(a)
type(b)
you'll see that a is 'xrange' and b is a 'list'
if you do:
dir(a)
dir(b)
you'll see that a has all of the list methods (which includes slicing)
whereas b has none.
xrange is a generator object so slicing is not relevant, although
you could assemble a list from the generator using append,
that could then be sliced.
More information about the Python-list
mailing list