Circular iteration on tuple starting from a specific index

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Jun 1 06:14:52 EDT 2017


guillaume.paulet at giome.fr wrote:
> def cycle_once(iterable, start):
>     return chain(islice(iterable, start, None), islice(iterable, start))

Another variation, maybe slightly more efficient:

from itertools import islice, cycle

def cycle_once(iterable, start):
     return islice(cycle(iterable), start, start + len(iterable))

-- 
Greg



More information about the Python-list mailing list