New submission from David Lindquist:

The roundrobin example in the Recipes section of the itertools documentation 
(http://docs.python.org/3/library/itertools.html#itertools-recipes) is overly 
complex. Here is a more straightforward implementation:

def roundrobin(*iterables):
    "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
    sentinel = object()
    it = chain.from_iterable(zip_longest(fillvalue=sentinel, *iterables))
    return (i for i in it if i is not sentinel)

Not only is it one-third the lines of the existing example, benchmarks show it 
to be more than twice as fast.

See attached patch file.

----------
assignee: docs@python
components: Documentation
files: roundrobin.patch
keywords: patch
messages: 211907
nosy: david.lindquist, docs@python
priority: normal
severity: normal
status: open
title: Improved roundrobin itertools recipe
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file34180/roundrobin.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20727>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to