[issue32099] Use range in itertools roundrobin recipe

2017-11-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: New changeset 0858495a50e19defde786a4ec050ec182e920f46 by Raymond Hettinger in branch 'master': bpo-32099 Add deque variant of roundrobin() recipe (#4497) https://github.com/python/cpython/commit/0858495a50e19defde786a4ec050ec182e920f46 -- __

[issue32099] Use range in itertools roundrobin recipe

2017-11-23 Thread Raymond Hettinger
Change by Raymond Hettinger : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue32099] Use range in itertools roundrobin recipe

2017-11-21 Thread Raymond Hettinger
Change by Raymond Hettinger : -- pull_requests: +4434 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue32099] Use range in itertools roundrobin recipe

2017-11-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: But why use less efficient code? Is my code worse? -- ___ Python tracker ___ ___ Python-bugs-lis

[issue32099] Use range in itertools roundrobin recipe

2017-11-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: Really, I don't give a whit about the micro-benchmarks -- that completely misses the point. The recipes are primarily intended to have educational value on ways to use itertools, deques, and whatnot. For itertools, I'm satisfied with new variable name and

[issue32099] Use range in itertools roundrobin recipe

2017-11-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Today I have published a similar recipe on Python-Ideas. It uses popleft/append instead of __getitem__/rotate. def roundrobin(*iterables): "roundrobin('ABC', 'D', 'EF') --> A D E B F C" nexts = deque(iter(it).__next__ for it in iterables) popleft

[issue32099] Use range in itertools roundrobin recipe

2017-11-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: While we're on the topic, I had some thought of also adding a similar recipe to https://docs.python.org/3/library/collections.html#deque-recipes . The alternative recipe is slower is common cases but doesn't degrade when there are a huge number of iterabl

[issue32099] Use range in itertools roundrobin recipe

2017-11-21 Thread Roundup Robot
Change by Roundup Robot : -- pull_requests: +4425 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Actually I tried to test if this implementation can cause a crash due to using deeply nested iterators (like in issue14010). For example in next(roundrobin(*([[]]*N + [[1]]))). But if there is such problem here, roundrobin() becomes unusable due to quadrati

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I agree that using binary tree would be excessively here. I just wondering if there is a simple way to get rid of the quadratic complexity. In any case this does not matter much until you work with many hundreds or thousands of iterables. -- _

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Raymond Hettinger
Change by Raymond Hettinger : -- Removed message: https://bugs.python.org/msg306629 ___ Python tracker ___ ___ Python-bugs-list maili

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: Serhiy, I think you're focusing on an irrelevant edge case and reading too much into the recipe. You could create an underlying binary tree with O(n) iteration and O(log n) deletion but then that completely misses the point of the itertools recipes and wo

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: roundrobin() has quadratic computational complexity. For example list(roundrobin(*([[1]]*N))). Is there a way to make it with linear complexity? -- nosy: +serhiy.storchaka ___ Python tracker

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Raymond Hettinger
Change by Raymond Hettinger : -- keywords: +patch pull_requests: +4424 stage: needs patch -> patch review ___ Python tracker ___ ___

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Tim Peters
Tim Peters added the comment: I agree the current recipe strikes a very nice balance among competing interests, and is educational on several counts. s/pending/numactive/ # Remove the iterator we just exhausted from the cycle. numactive -= 1 nexts = cycle(islice(nexts, numactive))

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: IMO, George Sakkis's original version is better than the TJR's proposed revision which has three separate adjustments by one and adds to extraneous functions which aren't central to the example. Dubslow's alternative at least avoids the three offsets by o

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: docs@python -> rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubsc

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Dubslow
Dubslow added the comment: Er, in my first message, make that "(yield from tup for tup in zip_longest(*iters, usefill=False))" -- ___ Python tracker ___ __

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Dubslow
Dubslow added the comment: Perhaps the loop variable could be renamed to "len_minus_1" or some such something which is more semantic to the algorithm. -- ___ Python tracker __

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Dubslow
Dubslow added the comment: Regarding the current bug more specifically, I think a few comments would go a long way to helping readers understand the code. And also, I do think the (1, +1, -1) is less readable, simply because it doesn't follow the most common usage patterns of range, where you

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Dubslow
Dubslow added the comment: Note that this follows a bit of discussion on python-ideas, in two threads: https://mail.python.org/pipermail/python-ideas/2017-November/047920.html https://mail.python.org/pipermail/python-ideas/2017-November/047989.html I agree the zip_longest-derived solution is

[issue32099] Use range in itertools roundrobin recipe

2017-11-20 Thread Terry J. Reedy
New submission from Terry J. Reedy : The itertools roundrobin recipe has an outer loop executed a preset number of times. It is currently implemented with two assignments and a while loop. https://docs.python.org/3/library/itertools.html#itertools-recipes These can be replaced with a for loop u