Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (Retired) Tuples Combo

Problem with "combo" challenge.

Hello,

I don't know why my code doesn't work. Can you help me?

Best regards, Robert

zippy.py
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
# If you use .append(), you'll want to pass it a tuple of new values.
def combo(it1, it2):
  list = []
  i = 0
  while i < len(it1):
    list.extend("{}{}".format(it1[i], it2[i]))
    i = i + 1
  return list

1 Answer

Hi Robert

Actually there is nothing wrong with the way you approached this challenge, although you should use the append method rather than the extend method as you are creating a new list. Also because the challenge requires the second part of each tuple to be in quotes, it can become quite hard to accomplish this using string concatenation or the format method. I prefer to create the tuple and then add it to the list.

see below.

# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
# If you use .append(), you'll want to pass it a tuple of new values.

def combo(it1, it2):
  list = []
  i = 0
  while i < len(it1):
    tup=(it1[i],it2[i]) # create the tuple and then append to the list
    list.append(tup)
    i = i + 1
  return list