Circular Buffer

bearophile bearophileHUGS at lycos.com
Thu Feb 13 10:03:21 PST 2014


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


More information about the Digitalmars-d-learn mailing list