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

Not sure why this is not acceptable for a solution

Using PyCharm, I can show the right results when calling function through print(). The editor for the challenge in instances.py won't accept. I've tried editing in multiple ways, still not getting the coveted "well done" that keeps me going after a hard day coding.

I have even gone and copy pasted others folks solutions and those don't work either. Almost all the challenge editors have been buggy, but I usually ctrl+c my code, hit restart, ctrl+v and it works. I'm fed up with this one, been trying all day and can't get it to go through. With all the editors on this site been so finicky, I'm not sure if it's me or not, though I know most the time a program isn't working, I can usually be blamed.

Not sure I care anymore after typing this, just letting folks know that if they're having issues, they're not alone.

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


def combiner(my_list):
    words = ''
    num = 0
    for item in my_list:
        if isinstance(item, str):
            words = item + words

        if isinstance(item, (int, float)):
            num = num + item

    return words + str(num)
Laurens Salcedo Valdez
Laurens Salcedo Valdez
3,117 Points

I think the Return won't give a you a combination of the words and integers of both lists. In this case you are just interjoining two lists, which would generate one single list with -> return words + str(num). Look up the function .join(), that one would help you in this case.

So for example: ... succesful = ''.join("stringlist") + str(sum("integerlist") return succesful

''.join -> will join the strings together without space as your - '' - indicates no spacing Same goes for you integerlist.

My own code: thing = ["apple", 5.2, "dog", 8] def combiner(thing): nums = [x for x in thing if isinstance(x,(float, int))] strings = [x for x in thing if isinstance(x, str)] succesful = ''.join(strings) + str(sum(nums)) print(succesful)

2 Answers

Steven Parker
Steven Parker
229,670 Points

You're really close, but the challenge is expecting to see the strings joined in order. Take a look at this code:

            words = item + words

This line joins the new item in front of the existing collection instead of behind, so the ordering gets reversed. Just do it the other way and you'll pass.

Switching item and words around did it....It's amazing how something so small can cause so much agony! Appreciate the advice from you folks. Good luck to you!