April 2018
Intermediate to advanced
408 pages
10h 42m
English
The repeat() function seems like an odd feature: it returns a single value over and over again. It can serve as an alternative for the cycle() function when a single value is needed.
The difference between selecting all of the data and selecting a subset of the data can be expressed with this. The function (x==0 for x in cycle(range(size))) emits a [True, False, False, ...] pattern, suitable for picking a subset. The function (x==0 for x in repeat(0)) emits a [True, True, True, ...] pattern, suitable for selecting all of the data.
We can think of the following kinds of commands:
all = repeat(0) subset = cycle(range(100)) choose = lambda rule: (x == 0 for x in rule)# choose(all) or choose(subset) can ...