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

How to list items in tuples as individual items in a list of different paired tuples

working on this exercise with a couple of days, am I over complicating whats being looked for? I've looked up online but couldn't find anything that helps. any help/direction would be very much appreciated

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(first,second):
    tlist = []
    for x in tuple(first):
        for y in tuple(second):
            return tlist.append((x,y))

2 Answers

Steven Parker
Steven Parker
229,744 Points

:point_right: You don't want to return until you finish building the list.

Also, nested loops would generate too many items — you only want one item per list index, using both lists at the same time. So you could do something like this:

def combo(first, second):
    tlist = []
    for x in range(0, len(first)):  # rely on both lists having the same length
        tlist.append((first[x], second[x]))
    return tlist

Or you could do it in one step using the zip function:

def combo(first, second):
    return list(zip(first, second))
Robin *
Robin *
5,670 Points

could also use a list comprehension for one-liner

def combo(x, y):
    return [(x[i], y[i]) for i in range(0, len(x))]