Circular iteration on tuple starting from a specific index

guillaume.paulet at giome.fr guillaume.paulet at giome.fr
Tue May 30 18:13:56 EDT 2017


Hi Beppe !

There are some powerful tools in the standard *itertools* module, you 
should have a look at it :)
https://docs.python.org/3/library/itertools.html

This is what I would do to cycle over you iterable without making 
several copies of it.

```
from itertools import islice, chain

def cycle_once(iterable, start):
     return chain(islice(iterable, start, None), islice(iterable, start))

my_iterable = ('A','B','C','D','E','F','G','H')

for e in cycle_once(my_iterable, 2):
     print(i)
```

Ps: I am pretty new to how a mailing list works. If I answered the wrong 
way, do not hesitate to tell me :)



More information about the Python-list mailing list