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

Code works on editor, but not in treehouse...

I'm sure this isn't a very elegant solution, but it's the best I could think of. It works in my editor, but not when I submit to Treehouse. Any thoughts?

# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]

def combo(*args):
    full_list = []
    x_tuple = ()
    y_tuple = ()
    z_tuple = ()
    for items in args:
        index_positions = list(enumerate(items))

    for x,y in full_list:
        if x == 0:
            x_add = x_tuple + (y,)
            x_tuple = x_add
        elif x == 1:
            y_add = y_tuple + (y,)
            y_tuple = y_add
        elif x == 2:
            z_add = z_tuple + (y,)
            z_tuple = z_add
    full_list = [x_tuple,y_tuple,z_tuple]


2 Answers

Steven Parker
Steven Parker
228,991 Points

:warning: Be careful about testing a challenge in an external REPL or IDE.

If you have misunderstood the challenge, it's also very likely that you will misinterpret the results.

In this case, you're making assumptions about the incoming data. Unlike the sample shown in the comments, the real test data may have more than 3 items and the items might not contain sequential numbers.

You'll need to write your function so it can work on iterable pairs of any length and with any contents. The good news is that a generic solution can actually be less complicated and more compact that what you have here.

Thanks Steven. I'll work on it. The instructions said: Assume the iterables will be the same length, which is why I went the route I did. I'll take what you suggest and hammer it out.

Steven Parker
Steven Parker
228,991 Points

Yes, you can assume they are the same length as each other. But not the same length as in the example.

Yeah, makes sense now. Solved. Thank you, Steven! The answer was so much simpler. :) Took 6 lines of code.