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

Jason Smith
Jason Smith
8,668 Points

TypeError: 'int' object not iterable

i don't see how i can solve this problem without looping through it

instances.py
def combiner(list):
    for string, integer in list:
        if isinstance(string(str)) == True:
            string.join("")
        if isinstance(integer(int,float)) == True:
            integer += integer
    return string + str(integer)

2 Answers

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Jason,

You do want to iterate through the list, but remember the proper syntax for for in loops. You choose one temporary variable name to represent the list element on each iteration:

for element in my_list:
    # do something with element

As such, you can't distinguish between the element types in the loop definition. Take another look at the syntax for isinstance to get an idea for how you can use your temporary variable to get the element's type.

You're also going to need to revisit the syntax for join().

Hope these point you in the right direction.

Cheers

Alex

Eduardo Valencia
Eduardo Valencia
12,444 Points

You wrote string(str), but string is not a function; it is a variable. You need to tell the program if your variable string is an instance of the class str, but you never told it what class you are checking it against.

Here is a link to the documentation on the function isinstance: https://python-reference.readthedocs.io/en/latest/docs/functions/isinstance.html

It also provides some examples that may help you out.