Skip to content

Instantly share code, notes, and snippets.

@Kwpolska
Created May 1, 2015 10:16
Show Gist options
  • Select an option

  • Save Kwpolska/6745cbac68d37ca3a594 to your computer and use it in GitHub Desktop.

Select an option

Save Kwpolska/6745cbac68d37ca3a594 to your computer and use it in GitHub Desktop.
# Don’t use this, use itertools.zip_longest() instead!
def alternate_all(*args):
ls = [iter(i) for i in args]
stops = 0 # cheat and get 9 LOC by making this a keyword argument
while stops != len(ls):
stops = 0
for l in ls:
try:
yield next(l)
except StopIteration:
stops += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment