擅长:python、mysql、java
<p>在<a href="http://docs.python.org/library/itertools.html" rel="noreferrer">^{<cd1>} documentation</a>中有一个配方:</p>
<pre><code>from itertools import cycle, islice
def roundrobin(*iterables):
"roundrobin('ABC', 'D', 'EF') --> A D E B F C"
# Recipe credited to George Sakkis
pending = len(iterables)
nexts = cycle(iter(it).next for it in iterables)
while pending:
try:
for next in nexts:
yield next()
except StopIteration:
pending -= 1
nexts = cycle(islice(nexts, pending))
</code></pre>