This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author david.lindquist
Recipients david.lindquist, docs@python
Date 2014-02-22.06:36:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1393051018.22.0.696460210134.issue20727@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-02-22 06:36:58david.lindquistsetrecipients: + david.lindquist, docs@python
2014-02-22 06:36:58david.lindquistsetmessageid: <1393051018.22.0.696460210134.issue20727@psf.upfronthosting.co.za>
2014-02-22 06:36:57david.lindquistlinkissue20727 messages
2014-02-22 06:36:56david.lindquistcreate