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

victor E
victor E
19,145 Points

not sure why this isn't working.

the example it shows as my output seems correct

combo.py
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
def combo(item1, item2):
    combined = []
    for i in range(0, len(item1)):
        combined.append((item1[i],item2[1]))
    return combined
Kyrylo Troian
Kyrylo Troian
570 Points

You are generating an index with for in, but you use constant 1 as an index from item2. for in loop works with iterable and generator objects, range is a generator function and list is iterable. You can simplify working with lists:

for n in items:
    combined.append(n)

Also, think about renaming variables item1 and item2, item_1and item_2 or numbers and characters will be better.

For your needs, you may use zip():

combined = list()
    for i, j in zip(item_1, item_2):
        combined.append((i, j))
    return combined
victor E
victor E
19,145 Points

Kyrylo, thank you that does work for the desired problem but it does not want me to use zip. this is the message it gives me lol

Bummer: Don't use zip()! I know it exists but the point of this challenge is to solve the problem yourself.

1 Answer

Steven Parker
Steven Parker
230,274 Points

It looks like you just have a typo. The index for item2 is a 1 (one) instead of the letter "i":

        combined.append((item1[i],item2[1]))    # original code
        combined.append((item1[i],item2[i]))    # fixed

Note that the "bummer" message doesn't show your output, but an example of what it is expecting.