Message211907
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. |
|
Date |
User |
Action |
Args |
2014-02-22 06:36:58 | david.lindquist | set | recipients:
+ david.lindquist, docs@python |
2014-02-22 06:36:58 | david.lindquist | set | messageid: <1393051018.22.0.696460210134.issue20727@psf.upfronthosting.co.za> |
2014-02-22 06:36:57 | david.lindquist | link | issue20727 messages |
2014-02-22 06:36:56 | david.lindquist | create | |
|