Sorry. Unfortunately I had a mistake.
Alon Snir
Date: Thu, 23 Nov 2017 12:29:47 +1100
From: Steven D'Aprano <st...@pearwood.info>
To: python-ideas@python.org
Subject: Re: [Python-ideas] Rewriting the "roundrobin" recipe in the itertools
documentation
Message-ID: <
On Wed, Nov 22, 2017 at 11:28:20AM +, Alon Snir wrote:
> It would be faster with ‘deque’:
It isn't. According to my testing, your version with deque is
approximately two times slower than the version from toolz.itertoolz
that Wes quotes.
--
Steve
[mailto:wes.tur...@gmail.com]
Sent: Wednesday, November 22, 2017 04:11
To: Alon Snir <alons...@hotmail.com>
Cc: python-ideas@python.org
Subject: Re: [Python-ideas] Rewriting the "roundrobin" recipe in the itertools
documentation
Here's toolz.itertoolz.interleave():
def
Here's toolz.itertoolz.interleave():
def interleave(seqs):
""" Interleave a sequence of sequences
>>> list(interleave([[1, 2], [3, 4]]))
[1, 3, 2, 4]
>>> ''.join(interleave(('ABC', 'XY')))
'AXBYC'
Both the individual sequences and the sequence of sequences may be
infinite
def roundrobin(*iterables):
"roundrobin('ABC', 'D', 'EF') --> A D E B F C"
nexts = [ iter(it).__next__ for it in iterables ]
i = 0
while nexts:
i %= len(nexts)
try:
yield nexts[i]()
except StopIteration:
del nexts[i]
else:
21.11.17 11:44, Serhiy Storchaka пише:
The roundrobin() implementation in recipes has quadratic time for large
number of iterables. As well as all other proposed implementations. This
is a problem if you use it with hundreds or thousands of iterables. For
example:
The roundrobin() implementation in recipes has quadratic time for large
number of iterables. As well as all other proposed implementations. This
is a problem if you use it with hundreds or thousands of iterables. For
example:
list(roundrobin(*([[1]]*1000)))
next(roundrobin(*([[]]*1000
On 11/16/2017 5:57 PM, Terry Reedy wrote:
On 11/16/2017 2:56 PM, Terry Reedy wrote:
Correct off-by-one error. I should have tested with an edge case such as
print(list(roundrobin('ABC', '')))
The following combines 3 statements into one for statement.
def roundrobin(*iterables):
I find this refactored code intriguing. While I would not suggest changes
to the itertools recipes,
it is a pleasant exercise to think of alternative recipes with an itertools
way.
There are a few third-party libraries dedicated to itertools recipes. For
example, more-itertools
has an
On 11/16/2017 2:42 PM, brent bejot wrote:
I think the idea behind the original recipe is that when one of the
inner lists has been iterated through, it is removed and never looked at
again. Imagine the following scenario:
L is a list which contains one million empty lists and also a list
On 11/16/2017 2:56 PM, Terry Reedy wrote:
Correct off-by-one error. I should have tested with an edge case such as
print(list(roundrobin('ABC', '')))
The following combines 3 statements into one for statement.
def roundrobin(*iterables):
"roundrobin('ABC', 'D', 'EF') --> A D E B F C"
On Thu, Nov 16, 2017 at 07:56:21AM -0600, bunslow wrote about the
roundrobin recipe in the itertools docs:
> However, it is remarkably unpythonic, in my opinion
[...]
> Things that strike me as unpythonic: 1) requiring the total number of input
> iterables 2) making gratuitous use of `next`, 3)
I like yours better. Plenty of recipes sit on top of other recipes, e.g.,
pairwise sits on top of tee.
On Thursday, November 16, 2017 at 8:57:29 AM UTC-5, bunslow wrote:
>
> For taking values alternately from a series of iterables, there's two
> primary functions:
>
> builtin.zip
>
On 11/16/2017 05:56 AM, bunslow wrote:
I realize at the end of the day this is a pretty trivial and ultimately
meaningless nit to pick,
Not at all -- documentation is extremely important.
but I've never
contributed before and have a variety of similar minor pain points in the
docs/stdlib,
For taking values alternately from a series of iterables, there's two
primary functions:
builtin.zip
itertools.zip_longest
zip of course stops when the shortest iterable ends. zip_longest is
generally a useful substitute for when you don't want the zip behavior, but
it fills extra values in the
15 matches
Mail list logo