Message55148
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 |
|
Date |
User |
Action |
Args |
2007-08-23 16:12:56 | admin | link | issue1757395 messages |
2007-08-23 16:12:56 | admin | create | |
|