Russel Winder:

I had a quick go at doing a Python 3 version using PyTest:


def provide(sourceSequence, resultLength):
return (sourceSequence[i % len(sourceSequence)] for i in range(resultLength))

def provideReverse(sourceSequence, resultLength):
    sourceLength = len(sourceSequence)
return (sourceSequence[sourceLength - 1 - i % sourceLength] for i in range(resultLength))

Take also a look at itertools.cycle.

Bye,
bearophile

Reply via email to