Python Object-Oriented Python Inheritance Instances

Patrick Jimosse
Patrick Jimosse
1,995 Points

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
2,837 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
177,508 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.

Patrick Jimosse
Patrick Jimosse
1,995 Points

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!

Steven Parker
Steven Parker
177,508 Points

Patrick Jimosse — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!