Python Python Collections (2016, retired 2019) Tuples Combo

victor escarcega
victor escarcega
7,599 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
7,599 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
203,990 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.