[Python-Dev] xrange identity crisis
Martin v. Loewis
martin@v.loewis.de
04 Jun 2002 23:47:00 +0200
Guido van Rossum <guido@python.org> writes:
> The current xrange code (from SF patch #551410) uses the xrange object
> as both an iterator and iterable, and has an extra flag to make things
> work right when the same object is iterated over more than once.
> Without doing more of a review, I can only say that I'm a but
> uncomfortable with that approach. Something like the more recent code
> that Raymond H added to listobject.c to add a custom iterator makes
> more sense. But perhaps it is defensible.
The main defense is that the typical use case is
for i in xrange(len(some_list))
In that case, it is desirable not to create an additional object, and
nobody will notice the difference.
Regards,
Martin