Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Tuples Combo

Louis Puster
Louis Puster
5,419 Points

This error message is no help. Where am I going wrong?

I am working on the Tuples challenge in the Python Collections course.

When I run my code, I get an error message that is utterly confusing. Help!

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

zippy.py
# 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(item1, item2):
    output = []
    for thing1 in item1:
      for thing2 in item2:
        templist = (thing1, thing2)
        output.append(templist)
        return output
    return output

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Yes, the error message is misleading because the first element it gets back is correct... its all the others that are incorrect. This solution doesn't require any nested for loops.

First we make a new empty list. Now, they're nice and have told us that both lists they're sending are the same length. So we don't have to worry about that. Now we go down the length of x (which also happens to be the length of y). And then we simply append x at the index of z and y at the index of z. Hope this helps!

def combo(x, y):
  myList = list()
  for z in range(len(x)):
    myList.append((x[z], y[z]))
  return myList
Louis Puster
Louis Puster
5,419 Points

It took me a second to sort out what you are doing here (the addition of range was unexpected for me), but now I get it. Thanks!