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

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

this is umbelivable!!!!!!

i made this code : def combo(*com): return list(enumerate(com, start=1)) and it doesn't accept it and my code it's workin for the output and still not ok

somebody can tell me what is going on here please

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

def combo(*com):
    l_1 = []
    count = 0
    for a,b in com:
        for x in b:
            l_1.append((a[count], x))
            count +=1

    return l_1

2 Answers

Steven Parker
Steven Parker
231,269 Points

Don't expect the challenge to test the code using the sample.

The sample is just to show you an example of how it should work, not the exact data that it will be tested with.

Here's a few hints:

  • combo should take two arguments
  • both arguments will be iterables
  • remember that you can "Assume the iterables will be the same length."
Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

thank you. i am sorry that i asked too much but probebly i didn'unerstood well the question and that the example what it shows it's already two arguments. i am very new in python and i try to understand it as well is posible and for me this was the easiest solution with (*).thank you again

Ryan S
Ryan S
27,276 Points

Just to add on to Steven's answer, the way you are iterating through your for loop assumes that the input argument comes in the form of a tuple (or a list) that contains each iterable as separate items.

For your function to work correctly, your input argument would need to come in the form:

my_input = ([1, 2, 3], 'abc')  # a tuple of arguments
combo(my_input)

Because you are using the star operator in the function definition, you will actually be iterating through a tuple containing a tuple:

for a, b in (([1, 2, 3], 'abc'), ):  # tuple containing a tuple as the one and only item

So your for loop will successfully extract the values, which is why it is working locally for you.

However, as Steven mentioned, the function will need to take 2 individual arguments (not a tuple of arguments), and by using the star operator in the function definition, your "com" variable in the for loop is actually of the form:

for a, b in ([1, 2, 3], 'abc'): # tuple containing two items

Now there is a variable mismatch when trying to pull out the values.

A rough way of fixing this is to immediately convert your input arguments to a one-item tuple: com = (com, ) so your loop logic can remain exactly as it is. This will work to pass the challenge, but it is not really an ideal solution for what the challenge is asking.

I'd recommend redoing it with Steven's points in mind. Going beyond the specific instructions of the challenge will usually cause problems.

Good luck.

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

and thank you to! this was the best explication till now and even if i am new in this i understood. i appreciate your patience to describe step by step. i read your message just 5 minutes ago and i already know how to rewrite it.