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

what is wrong with is instance()?

def combiner(mylist): sum = 0 str ="" for item in mylist: if isinstance(item,str): str += item elif isinstance(item,(int,float)): sum += item else: pass return str+str(sum)

instances.py
def combiner(mylist):
    sum = 0
    str =""
    for item in mylist:
        if isinstance(item,str):
            str += item
        elif isinstance(item,(int,float)):
            sum += item
        else:
            pass
    return str+str(sum)    

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Be careful of your variable name choices. By using str as a variable choice the code is overriding the local reference to the build-in type str. This means at the str + str(sum) statement, you are really trying to do "abcde" + "abcde"(sum).

:point_right: rename variable str to a non-builtin keyword