August 2018
Intermediate to advanced
332 pages
9h 12m
English
We are already familiar with the built-in enumerate() function that, given an iterable, will return another one on which the element is a tuple, whose first element is the enumeration of the second one (corresponding to the element in the original iterable):
>>> list(enumerate("abcdef"))[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (5, 'f')]
We wish to create a similar object, but in a more low-level fashion; one that can simply create an infinite sequence. We want an object that can produce a sequence of numbers, from a starting one, without any limits.
An object as simple as the following one can do the trick. Every time we call this object, we get the next number of the sequence ad infinitum:
class NumberSequence: ...