On Fri, Jul 29, 2011 at 3:36 PM, Billy Mays <no...@nohow.com> wrote: > Is xrange not a generator? I know it doesn't return a tuple or list, so > what exactly is it? Y doesn't ever complete, but x does. > > x = (i for i in range(10)) > y = xrange(10)
xrange() does not return a generator. It returns an iterable xrange object. If you want the iterator derived from the iterable xrange object, you can get it like this: iterator = y.__iter__() See http://docs.python.org/library/functions.html#xrange for the definition of the xrange object. http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/ seems to cover the differences between iterables, iterators, and generators pretty well. Some more reading: http://docs.python.org/howto/functional.html http://www.python.org/dev/peps/pep-0255/ http://www.python.org/dev/peps/pep-0289/ -- Jerry -- http://mail.python.org/mailman/listinfo/python-list