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

Istvan Balogh
Istvan Balogh
1,505 Points

TypeError: combiner() takes 0 positional arguments but 1 was given

I'm stuck at this code challenge, anyone can point me to the right direction?

instances.py
def combiner():
    combined_list = "".join(filter(lambda i: isinstance(i, str), list))
    summed_nr = sum(filter(lambda i: isinstance(i, (float, int)), list))
    print(combined_list + str(summed_nr))
Istvan Balogh
Istvan Balogh
1,505 Points

After I have re-read the description of the task, I've updated my code as it calls for a function that takes a single argument, which is a list. Here's my updated code, that comes back with the error message: Didn't get the expected output

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

def combiner(list):
    summed_numbers = sum([i for i in list if isinstance(i, int) or isinstance(i, float)])
    joined_strings = "".join([i for i in list if isinstance (i, str)])
    print(joined_strings + str(summed_numbers))

3 Answers

Frances Angulo, here is a simpler solution although you may come up with a different way to return the string.

Istvan Balogh
Istvan Balogh
1,505 Points

I was going to post the same solution. This challenge took me a long time to solve and I had to look up things online, After my code was getting more and more complicated I found the aforementioned solution and I nearly started to bang my head into the wall when I realised that such a simple code could do the same.

The function should return the string not print. Make that change and you'll pass. Your current function returns None which is why you see Didn't get the expected output

Frances Angulo
Frances Angulo
5,311 Points

These concepts are foreign to me (eg. the .join and even the i for i). Is there a way to complete this challenge using simpler concepts that we've learned in the course? This challenge closes out the concept of super() and class inheritance for me.