Alexander Belopolsky wrote:
On Tue, Apr 29, 2008 at 10:36 PM, Guido van Rossum <[EMAIL PROTECTED]> wrote:
..
R = range(N)
for i in R:
for j in R:
....
You realize that in the snippet above whatever cycles you save by
creating R once, you give away by creating iter(R) twice.
I'm not so sure about that. Evaluating range(N) involves
a global lookup and Python function call, whereas extracting
an iterator from a C-implemented iterable doesn't.
The difference is likely to be even greater when
there are more arguments involved, such as range(m, n, s).
Also, the range may be getting computed elsewhere. There
are notational conveniences to being able to wrap the
description of a range up into a single object
that can be passed around and iterated over easily.
--
Greg
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com