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

Danish Saleem
Danish Saleem
7,965 Points

combo challenge

Hello ,

solved this problem using the following code

def combo(iter1,iter2): output = [] for index,item in enumerate(iter2): a = (iter1[index],iter2[index]) output.append(a) return output

however i am wondering if there is a way to use *args as a parameter in combo function than passing separate two iter parameters

combo.py
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]

4 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya Danish! This might help you to understand the question and the logic:

def combo(x, y):
  new_list = []
  count = 0
  for i in x:
    result = x[count], y[count]
    new_list.append(result)
    count += 1
  return new_list

I used the following, which will return the desired result, but it does not pass the task for some reason.

def combo(*args):
    return zip(*args)
print combo('abc', 'def')
# output: [('a', 'd'), ('b', 'e'), ('c', 'f')]
Herman Brummer
Herman Brummer
6,414 Points
def combo(input1, input2):
    counter = 0
    new_list = []

    for item in input1:
        x = item, str(input2[counter])
        new_list.append(x)
        counter = counter + 1

    return new_list        

I am trying the following, it has the correct output, but not accepted.

def combo(a, b): final = [] items_in_a = [] items_in_b = [] for item in a: items_in_a.append(item) for item in b: items_in_b.append(item) x = 0 for item in range(len(a)): final.append((a[x], b[x])) x += 1 return final