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

Frank Sherlotti
PLUS
Frank Sherlotti
Courses Plus Student 1,952 Points

Combo challenge please help.

QUESTION: --- Create a function named combo() that takes two iterables and returns a list of tuples. Each tuple should hold the first item in each list, then the second set, then the third, and so on. Assume the iterables will be the same length. --- It says I can use either append or enumerate to solve this. I'm more familiar with append and i'd rather learn how to use the enumerate method. The problem is I have no idea what i'm doing and I need some help with it please. If someone would please give me some type of example or maybe tell me what i'm doing wrong to solve my challenge that would be great. THANKS(:!

zippy.py
# 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.

def combo(first, second):
  empty = ()
  for index, value in enumerate(empty):
    first, second = empty
    list(enumerate(empty))    
  return empty

1 Answer

Hi,

You are on the right track. you need to visualise this question as that you need to make list of items from 2 different lists. It is given that both input lists are of same size so we don't need to do any validations on that part. You can iterate over one of the lists,along with saving its index position using enumerate, then access the second list using that index. Now you have items from each list in variables, you can append them to the output list using tuples.

Thanks

Frank Sherlotti
Frank Sherlotti
Courses Plus Student 1,952 Points

I still have absolutely no idea what i'm doing and its infuriating. I've hit a major wall at this point, and I don't understand why its with this challenge.