On Tue, Jun 04, 2002 at 04:08:08PM -0400, Oren Tirosh wrote: > It seems that the xrange object in the current CVS can't make up its mind > whether it's an iterator or an iterable: In 2.2, xrange had no "next" method, so it got wrapped by a generic iterator object. It was desirable for performance to have xrange also act as an iterator. See http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Objects/rangeobject.c.diff?r1=2.35&r2=2.36 for the change. See http://www.python.org/sf/551410 for the sf patch this comes from. However, the following code would give different results if 'iter(x) is x' for xrange objects: x = xrange(5) for a in x: for b in x: print a,b (it'd print "0 1" "0 2" "0 3" "0 4" if they were the same iterator, just as for 'x = iter(range(5))') so, it's necessary to return a *different* xrange object from iter(x) so it can start iterating from the beginning again. I think there's an optimization that *the first time*, iter(x) is x for an xrange object. Hm, the python cvs I have here is too old to have this optimization ... so I can't really tell you how it works now for sure. Jeff
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4