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

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!