Serhiy Storchaka <[email protected]> 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 = nexts.popleft
append = nexts.append
while nexts:
next = popleft()
try:
yield next()
except StopIteration:
pass
else:
append(next)
It is faster (10-25%) in all microbenchmarks that I did (Steven's benchmarks
for small number of iterables and my examples for large number of iterables).
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue32099>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com