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

srav
PLUS
srav
Courses Plus 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
Courses Plus 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.

Fergus Clare
Fergus Clare
12,120 Points

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:)