FAQ

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)
<ran...@...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

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

People

Translate

site design / logo © 2017 Grokbase