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

Ian Cole
Ian Cole
454 Points

Tuple Combo

So I've made it this far, I can get the two pieces into a tuple no problem. But what I assume to be happening is that the two for loops are skipping over every piece they iterate through until they get to the last item, thus only returning the last items of both arguments. But how do I prevent them from simply skipping over everything?

For example, if I run combo([1, 2, 3], 'abc') it only returns [(3, 'c')]

combo.py
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
def combo(arg1, arg2):
    big_list = []
    for item in arg1: # Assign the first piece of the packet (tuple)
        packet_piece1 = item
    for item in arg2: # Assign the second piece of the packet
        packet_piece2 = item
    staged_packet = (packet_piece1, packet_piece2) # Create the full packet
    big_list.append(staged_packet) # Slip the staged packet into the list
    return big_list # Return list

1 Answer

billy mercier
billy mercier
6,259 Points

here:

def combo(arg1, arg2):
alist = []
for n in range(len(arg1)): 
    alist.append((arg1[n], arg2[n])) 
return alist

this also works however was blocked in this test:

def combo(y, x):
return  list(((y[n], x[n])for n, i in enumerate(zip(y, x))))

Your for loop isn't skipping things, it rewrites itself everytime with the =. if you want your to add something to your variable you need to do x = x+1. if you don't and just do x = 1, x will become 1.

You should find a way to turn the variables int a tuple inside a for loop and append them in the list... all in a for loop.