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))
循环法是一种更好的方法,但您也可以使用chainizip_longest和{a3}:
如果没有值,请使用对象:
^{pr2}$看起来您想要} recipe :
roundrobin
^{使用中:
^{pr2}$相关问题 更多 >
编程相关推荐