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 Multiple Return Values

Jacob Rummel
Jacob Rummel
3,103 Points

Just want to clarify why my original solution wouldn't work for the Combo challenge

Hi,

I eventually did get the correct answer after looking up the questions/answers other students posed, but I was stuck for awhile and want to make sure I understand exactly why my original code wasn't working. Here it is:

def combo(base_iterable, second_iterable): 
    final_list = []  
    for base_iterable, second_iterable in range(len(base_iterable)): 
        necessary_tuple = (base_iterable, second_iterable) 
        final_list.append(necessary_tuple)
    return final_list

I know the problem is my for loop but I'm not exactly sure why it kept triggering a type error (can't iterate over an int). Thanks!

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

Good question! In the line:

for base_iterable, second_iterable in range(len(base_iterable)): 

the built-in range function produces a series of single integers. The for loop is looking for two items to unpack into the loop variables base_iterable and second_iterable. When the for loop tries to iterate over the single integer to get the two items it raises the error TypeError: 'int' object is not iterable.

Post back if you have more questions. Good Luck!!

Chris Walker
Chris Walker
5,004 Points

In your code, range steps through a set numbers. If you're to go this route, I'd use this to get the index for your two passed in variables. something like...necessary_tuple = (base_iterable[i], second_iterable[i]) .