@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
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
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),
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
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
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
>
>
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
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
> >
> >
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
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
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
11 matches
Mail list logo