(*iterables)
| 1 | from itertools import cycle, islice |
| 2 | |
| 3 | def roundrobin(*iterables): |
| 4 | pending = len(iterables) |
| 5 | nexts = cycle(iter(iterable).next for iterable in iterables) |
| 6 | while pending: |
| 7 | try: |
| 8 | for next in nexts: yield next() |
| 9 | except StopIteration: |
| 10 | pending -= 1 |
| 11 | nexts = cycle(islice(nexts, pending)) |