"Generics in Swift" was retired on May 31, 2020.

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

Blake Handson
Blake Handson
1,642 Points

Can someone please explain this code challenge solution ?

Ok, so I think I kind of understand what's going on in this code challenge solution.

Here's what me thinks:

-first the function is defined -a tuple is created to hold values from the iterables -the index and value of iter1 is being matched with the index and value of iter2 and added to the output tuple

Am I getting this completely mixed up ?

Thanks :)

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.
##iterables are just a list or something you can iterate through haha

def combo(iter1, iter2): 
    output = (): 

    for index, value in enumerate(iter1):    
        output.append((value, iter2[index]))

    return(output)

Hi Blake,

This code won't pass as it is currently written. You have a few errors where you initialize your output variable.

output = ():

You have a colon at the end of the line which has to be removed and the output should be a list, not a tuple.

Tuples are immutable which means you can't change them by appending items to it.

1 Answer

Steven Parker
Steven Parker
231,236 Points

It think you have the idea but I might state it a bit differently:

The indices are being matched up .. and then the values associated with them in each iterable are being combined into a tuple, which is then appended to your master list of tuples.

Blake Handson
Blake Handson
1,642 Points

Awesome, thanks Steven I understand now. Thanks for you reply.