Implementation of combo()

Submitted on 22 February 2015 at 21:34 UTC
2276 views

Section 1 (python)

# combo(['swallow', 'snake', 'parrot'], 'abc')
# Output:
# [('swallow', 'a'), ('snake', 'b'), ('parrot', 'c')]
# If you use list.append(), you'll want to pass it a tuple of new values.
# Using enumerate() here can save you a variable or two.

# It helps seeing what it should look like before:
# combo(['swallow', 'snake', 'parrot'], 'abc')
# ...and the result after:
# [('swallow', 'a'), ('snake', 'b'), ('parrot', 'c')]

def combo(one, two):
  results = []
  for step, value in enumerate(two): # same length, remember?
    results.append((one[step], value))
  return results
  

Raw · Download

Pastee