On 8/26/2015 8:21 AM, Tim Chase wrote:

a, b, c = (x for x in range(3)) # a generator for instance

Since range() *is* a generator, why not just use

In Python 3, range is a sequence class with a separate iterator class

>>> r = range(3)
>>> r
range(0, 3)
>>> iter(r)
<range_iterator object at 0x00000000034682D0>

Like all sequences, a range object can be iterated multiple times as a new iterator is used each time.

>>> list(r)
[0, 1, 2]
>>> list(r)
[0, 1, 2]

--
Terry Jan Reedy

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

Reply via email to