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 (2016, retired 2019) Tuples Combo

Why is this not working? Output seems right but saying nope.

It says Example output: combo('abc', 'def') => [('a', 'd'), ('b', 'e'), ('c', 'f')] but that seems to be right

combo.py
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
def combo(x,y):
    output = []
    for index, item in enumerate(y):
        atuple = (index, item)
        output.append(atuple)
    return output

1 Answer

andren
andren
28,558 Points

The error message is just illustrating what it expects your code to return, it is not showing what your code actually does return. If your code is ran with 'abc' and 'def' as the arguments then the result will actually be: [(0, 'd'), (1, 'e'), (2, 'f')].

In your code you insert the index of the loop as the first element, you never actually reference the x parameter within your function at all. Your code is quite close though, all you need to do to fix it is to reference x and use the index to pull out the letter at the same index as the one pulled from y.

Like this:

def combo(x,y):
    output = []
    for index, item in enumerate(y):
        atuple = (x[index], item)
        output.append(atuple)
    return output

Oh OK thank you