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

Laknath Gunathilake
Laknath Gunathilake
1,860 Points

Need some guidance on passing this challenge

Need some guidance on passing this challenge

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():
    h=[]
    g=[]
    h=tuple(combo[0])
    g=tuple(combo[1])
    for step in combo:
        return ('{}:{}'.format(g[0],h[0]))+('{}:{}'.format(g[1],h[1]))

2 Answers

Russell Sawyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Russell Sawyer
Front End Web Development Techdegree Student 15,705 Points

The enumerate function is a built-in function in Python and adds a counter to an iterable.

Here is some information on enumerate in the python docs. https://docs.python.org/3/library/functions.html?highlight=enumerate#enumerate

Using the zip function is by far the easiest although you haven't been introduced to it yet in the course here's some documentation. https://docs.python.org/3/library/functions.html?highlight=enumerate#zip

def combo(item1, item2):
    new_list = []
    for index, item in enumerate(item2):           
        new_list.append((item1[index], item))
    return new_list
Freddy Venegas
Freddy Venegas
1,226 Points

This was very helpful, thanks for the links as well.