Skip to content

Instantly share code, notes, and snippets.

@benoit-intrw
Created November 16, 2016 16:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoit-intrw/1471c4126554d700b79fddf2cd3a4bf9 to your computer and use it in GitHub Desktop.
Save benoit-intrw/1471c4126554d700b79fddf2cd3a4bf9 to your computer and use it in GitHub Desktop.
def take(iterable, num):
for i, elem in enumerate(iterable):
yield elem
if i + 1 == num:
break
def chain_pop(*iterable):
for elem in iterable:
while True:
try:
el = elem.pop()
yield el
except IndexError:
break
l1 = ['a', 'b', 'c']
l2 = ['d', 'e', 'f']
l3 = ['g', 'h', 'i']
print [el for el in chain_pop(l1, l2, l3)]
l1 = ['a', 'b', 'c']
l2 = ['d', 'e', 'f']
l3 = ['g', 'h', 'i']
print [el for el in take(chain_pop(l1, l2, l3), 4)]
print l1, l2, l3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment