Circular iteration on tuple starting from a specific index
Beppe
giuseppecostanzi at gmail.com
Wed May 31 11:20:01 EDT 2017
Il giorno mercoledì 31 maggio 2017 00:18:40 UTC+2, guillaum... at giome.fr ha scritto:
> 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)
> ```
for e in cycle_once(my_iterable, 2):
print(e)
perfect, thanks
>
> 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