def roundrobin(iterables):
 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))

def roundrobin ( iterables ) : 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 ) )
roundrobin take elements from iterables in a round-robin fashion .