Message306673
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). |
|
Date |
User |
Action |
Args |
2017-11-21 17:28:56 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, tim.peters, rhettinger, terry.reedy, docs@python, Dubslow |
2017-11-21 17:28:56 | serhiy.storchaka | set | messageid: <1511285336.42.0.213398074469.issue32099@psf.upfronthosting.co.za> |
2017-11-21 17:28:56 | serhiy.storchaka | link | issue32099 messages |
2017-11-21 17:28:56 | serhiy.storchaka | create | |
|