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

Input ['apple','dog',1,2] output ['appledog3'] Not excepting from treehouse, please help

This is giving the correctout put in my ide but not for treehouse?

instances.py
def combiner(args):
    my_list = ['apple','dog','banana',1,2,3.4]
    a = args
    my_list.append(a)
    string_list = [item for item in my_list if isinstance(item,str)]
    string_list.append(str(sum(item for item in my_list if isinstance(item,int) or isinstance(item,float))))
    strsum_list = ''.join(string_list)
    print([strsum_list])
combiner('test')

1 Answer

Steven Parker
Steven Parker
231,261 Points

I see a few issues:

  • the code needs to work on the arguments passed in, it should not have any built-in data
  • the function needs to return the result
  • it will not need to "print" anything
  • you only need to define the function, you won't need to call it yourself

I deleted the items in my_list and replaced print with return as well as getting rid of my personal call of the function but its still not working. Not sure what now. https://ghostbin.com/paste/evh6n

Steven Parker
Steven Parker
231,261 Points

Interesting resource, "ghostbin"! I had not seen that before. I wonder who funds that?

But the args should not be put inside another list:

    my_list = []          # instead lf all this...
    a = args
    my_list.append(a)
#-------------------------------------------------------
    my_list = args        # you could just do this

You could also just use "args" directly instead of having "my_list" at all.

And at the end, when you return the string, don't enclose it in another list.

I dont know who funds "Ghostbin" but it is a great pastebin replacement for a quick paste that you wont be keeping.

Also ok thankyou that fixed it.

Steven Parker
Steven Parker
231,261 Points

Apparently "pastebin" is blocked by my network security filter, "ghostbin" might be soon.

But you can share formatted code right here as I did, using the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

That sucks that your network filters it I guess theres always vpns and tor. Thanks that is good to know.