Skip to content

Instantly share code, notes, and snippets.

@Averroes
Created April 10, 2015 14:13
Show Gist options
  • Select an option

  • Save Averroes/f55093bcc1092be7089f to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/f55093bcc1092be7089f to your computer and use it in GitHub Desktop.
unpack a fixed number of elements from iterables of arbitrary length
# example.py
#
# Unpacking of tagged tuples of varying sizes
records = [
('foo', 1, 2),
('bar', 'hello'),
('foo', 3, 4),
]
def do_foo(x,y):
print('foo', x, y)
def do_bar(s):
print('bar', s)
for tag, *args in records:
if tag == 'foo':
do_foo(*args)
elif tag == 'bar':
do_bar(*args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment