Author asdutton
Recipients
Date 2007-07-20.09:12:21
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Could we have a splice function in itertools? I see there was once a roundrobin proposal (#756253), but it was three years ago ...

Here's an alternate implementation:

def splice(*args):
  """splice(*iterables) --> iterator
  Returns an iterator whose next() method returns an element from each of the iterables in turn before starting again with the first iterable."""
  iters = list(args)
  n = len(iters)
  i = 0
  while n>0:
    i %= n
    try:
      yield iters[i].next()
      i += 1
    except StopIteration, e:
      n -= 1
      iters[i:i+1] = []
  raise StopIteration
History
Date User Action Args
2007-08-23 16:12:56adminlinkissue1757395 messages
2007-08-23 16:12:56admincreate