1 | initial version |
The generator is defined correctly, but you're not using it in the right way.
Expression count()
creates a new instance of the generator; so the first time you call next()
it will give zero.
Instead, you should create it once, and then call next()
several times on the resulting object, e.g.:
sage: mycount = count()
sage: [mycount.next() for i in range(18)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
sage: mycount = count()
sage: [next(mycount) for i in range(18)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
sage: next(mycount)
18
sage: next(mycount)
19