what's the python for this C statement?
Terry Reedy
tjreedy at udel.edu
Mon Oct 20 17:33:05 EDT 2008
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
More information about the Python-list
mailing list