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)
CodePudding user response:
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