Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python function help, does someone can tell me why it doesent work?

my task is to write a python program removes all characters or strings from a string (text)
specified in a list (strings_list). I got it like this but this doesen’t work. Anybody can tell me what i got wrong or did I use a wrong function?
Thanks!!

def remove_strings(text, strings_list):
    for strings_list in remove_strings:
        strings_list.remove()
        
        text_cleaned = remove_strings("yes, no, maybe..",
                                      ["yes", ","])
    return text_cleaned
    print(text_cleaned)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


def removechar(text, strings_list):
    newstrings = []
    for i in strings_list:
            
        if text in i:
            newtext = ""
            newtext = i
            newtext = newtext.replace(text, "")
            newstrings.append(newtext)
        else:
            newstrings.append(i)

    print(newstrings)
    return(newstrings)

also, .remove() isnt a function, you would have to use .replace(text, "") instead

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading