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

Kishore Kumar
Kishore Kumar
5,451 Points

Create a function named combo() that takes two iterables and returns a list of tuples. Each tuple should hold the first

My Code:

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(iter1, iter2): output = []
for index, value in enumerate(iter1): output.append((value,iter2[index])) return output

Error: Bummer! Didn't get the right output. For example, expected (10, 'T') as the first item, got (10, 'T') instead.

3 Answers

Haider Ali
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Haider Ali
Python Development Techdegree Graduate 24,728 Points

Hi, I copied your code into the challenge and applied the correct indentation and it worked:

def combo(iter1, iter2): 
    output = []
    for index, value in enumerate(iter1): 
        output.append((value,iter2[index])) 
    return output
Kishore Kumar
Kishore Kumar
5,451 Points

Thanks Again, Haider. I just missed that. Thanks for catching

Yuan Gao
Yuan Gao
8,947 Points

Anyone knows what we can do if the number of iterables is unknown?