Lie Ryan wrote:

(which might be the more typical case). And I think range will be an iterator in the future, imitating the behavior of xrange. So it doesn't really matter anyway.

In 3.0, range is a class and range(arg) is a re-iterable instance of that class.

>>> a = range(10,2,-3)
>>> a
range(10, 2, -3)
>>> list(a)
[10, 7, 4]
>>> list(a)
[10, 7, 4]

Re-iterablility is handy if you want to iterate twice over the same range, especially is the range object is computed elsewhere.

Map and filter, on the other hand, produce one-use iterators. Filter takes one iterable as input and map takes many iterables. Both make no presumption that the inputs are re-iterable rather than a one-time iterators.

Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to