Python Python Collections (2016, retired 2019) Tuples Combo

srav
PRO
srav
Pro Student 3,476 Points

To return a list of tuples from 2 iterables given to a function

I am getting the following error: TypeError: sequence item 0: expected str instance, int found

I executed the same code in work spaces and it didn't thrown any error. Also, the returned list was same as expected. Am I missing some thing to solve this challenge ?? Any help is appreciated !!

Can you post your code?? It will be a little easier to help if you do.

Please post your code.

Remember to provide Markdown provided by the markdown cheatsheet below the answer box :arrow_heading_down:

srav
srav
Pro Student 3,476 Points

Hi, here is my function:

def combo(iter1, iter2):
    myList = []
    count = 0
    for i in iter1:
        myList.append((i,"".join(iter2[count:count+1])))
        count +=1
    return myList

2 Answers

def combo(iter1, iter2):
    myList = []
    count = 0
    for i in iter1:
        myList.append((i, iter2[count]))
        count += 1
    return myList

There's no need to use ''.join() or slicing.

What about this solution?

def my_funx(x,y):
   new_list = []
   for i in range(len(x)):
      new_list.append((x[i], y[i]))
   return new_list

That works too. (I also find your answer a little easier to read! :+1:)