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!

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


Leo Marco Corpuz
Leo Marco Corpuz
18,975 Points

Isinstance challenge

Here’s my updated code. Thanks!

def combiner(oldList):
    for item in oldList:
        if isinstance(item,string):
        elif isinstance(item,(float,int)):
return newList

1 Answer

Alex Koumparos
Alex Koumparos
Python Development Techdegree Student 36,886 Points

Hi Leo,

Let's run your code and start by finding the syntax errors:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/User/combiner.py", line 11
    return newList
SyntaxError: 'return' outside function

This is telling you that your return statement is indented at the wrong level.


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/User/combiner.py", line 5, in combiner
    if isinstance(item,string):
NameError: name 'string' is not defined

This is telling you that you've used an invalid term string in isintance. Let's look at the type of a string to check what the type's name is:

>>> type('hello')
<class 'str'>


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/User/combiner.py", line 10, in combiner
AttributeError: 'list' object has no attribute 'join'

Look at the syntax for the join() method. Note that it is a method on a string, not a method on a list. Note also that the list must comprise only strings.

Once these syntax errors are fixed, this is what we get when we run the code, passing it the suggested example code from Treehouse:

>>> combiner(["apple", 5.2, "dog", 8])
['apple', 'dog', '13.2']

This is because you do not return the result of joining the list, you return the list.

Hope these hints point you in the right direction.