Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Tuples Combo

victor escarcega
victor escarcega
15,083 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
558 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 escarcega
victor escarcega
15,083 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
222,348 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.