Steve R. Hastings wrote: > I wondered if the Python > compiler could, as a special case, turn: > > for i in range(n) > > into compiled code equivalent to > > for i in itr > > where "itr" is a lightweight iterator that returns the same values as > iter(range(n)).
Nope, out of the question for Python 2.x. Note that the the builtin range could be rebound, or a global range could appear in the module, at run time. There might even be a good reason to do so.... Point is, optimizing the call to range can break compatibility even in the for loop. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list