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

Josh Bennett
Josh Bennett
15,258 Points

OOP challenge task 1 of 1 : isinstance(). I get the right answer in Jupyter, sooo...?

have a look. in

stuff = ["apple", 5.2, "dog", 8]

def combiner(thing):
    nums = [x for x in stuff if isinstance(x, (float, int))]
    strings = [x for x in stuff if isinstance(x, str)]
    return ''.join(strings) + str(sum(nums))

combiner(stuff)

out 'appledog13.2'

instances.py
stuff = ["apple", 5.2, "dog", 8]

def combiner(thing):
    nums = [x for x in stuff if isinstance(x, (float, int))]
    strings = [x for x in stuff if isinstance(x, str)]
    return ''.join(strings) + str(sum(nums))

combiner(stuff)

2 Answers

Steven Parker
Steven Parker
231,275 Points

You only need to define the function, not call it (the validator will do that). Also, the function must work with the argument that is given to it. Don't make it rely on external data. You won't know what the validator will be passing it anyway.

Fix those issues and you'll pass.

You should replace "stuff" in your comprehensions to "thing". Otherwise, your function ignores the argument and just uses values for the global list defined above. Your tests should still work in Jupyter, but will be actually be acting on the data of the passed in argument instead of only seeming to. I have no idea if that will be accepted by our test environment, though, as I am having my own troubles getting a different version of that function to run.