Re: Circular iteration on tuple starting from a specific index

2017-06-02 Thread guillaume . paulet
@Gregory Ewing: you were right, your version without *chain* is faster and I quiet like it :) ``` from timeit import timeit from itertools import chain, cycle, islice def cycle_once_with_chain(sequence, start): return chain(islice(sequence, start, None), islice(sequence, start)) def cy

Re: Circular iteration on tuple starting from a specific index

2017-06-01 Thread Ian Kelly
On Thu, Jun 1, 2017 at 4:14 AM, Gregory Ewing wrote: > guillaume.pau...@giome.fr wrote: >> >> def cycle_once(iterable, start): >> return chain(islice(iterable, start, None), islice(iterable, start)) This assumes that iterable is restartable, which is not the case if iterable is itself an iter

Re: Circular iteration on tuple starting from a specific index

2017-06-01 Thread Gregory Ewing
guillaume.pau...@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),

Re: Circular iteration on tuple starting from a specific index

2017-05-31 Thread Beppe
Il giorno mercoledì 31 maggio 2017 00:18:40 UTC+2, guillaum...@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 y

Re: Circular iteration on tuple starting from a specific index

2017-05-30 Thread guillaume . paulet
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

Re: Circular iteration on tuple starting from a specific index

2017-05-30 Thread Peter Otten
Beppe wrote: > hi all > > I've a tuple, something like > > x = ("A","B","C","D","E","F","G","H",) > > I would want to iterate on all tuple's elements > starting from a specific index > with the difference that I would want to restart from the beginning when I > reach the end of the tupla > >

Re: Circular iteration on tuple starting from a specific index

2017-05-30 Thread Beppe
Il giorno martedì 30 maggio 2017 18:43:42 UTC+2, Ian ha scritto: > On Tue, May 30, 2017 at 10:25 AM, Beppe wrote: > > hi all > > > > I've a tuple, something like > > > > x = ("A","B","C","D","E","F","G","H",) > > > > I would want to iterate on all tuple's elements > > starting from a specific inde

Re: Circular iteration on tuple starting from a specific index

2017-05-30 Thread Beppe
Il giorno martedì 30 maggio 2017 18:51:50 UTC+2, MRAB ha scritto: > On 2017-05-30 17:25, Beppe wrote: > > hi all > > > > I've a tuple, something like > > > > x = ("A","B","C","D","E","F","G","H",) > > > > I would want to iterate on all tuple's elements > > starting from a specific index > > > >

Re: Circular iteration on tuple starting from a specific index

2017-05-30 Thread MRAB
On 2017-05-30 17:25, Beppe wrote: hi all I've a tuple, something like x = ("A","B","C","D","E","F","G","H",) I would want to iterate on all tuple's elements starting from a specific index something like Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 Type "help", "copyri

Re: Circular iteration on tuple starting from a specific index

2017-05-30 Thread Ian Kelly
On Tue, May 30, 2017 at 10:25 AM, Beppe wrote: > hi all > > I've a tuple, something like > > x = ("A","B","C","D","E","F","G","H",) > > I would want to iterate on all tuple's elements > starting from a specific index > > > something like > > Python 2.7.9 (default, Jun 29 2016, 13:08:31) > [GCC 4.9

Circular iteration on tuple starting from a specific index

2017-05-30 Thread Beppe
hi all I've a tuple, something like x = ("A","B","C","D","E","F","G","H",) I would want to iterate on all tuple's elements starting from a specific index something like Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for m