Trying to solve.
I have a string from a user input. And I want to reomove all special characters from a list = [',', '.', '"', '\'', ':',]
using the replace function I´m able to remove one by one. using somethin like:
string = "a,bhc:kalaej jff!"
string.replace(",", "")
but I want to do remove all the special chr. in one go. I have tried:
unwanted_specialchr = [',', '.', '"', '\'', ':',]
string = "a,bhc:kalaej jff!"
string.replace(unwanted_specialchr, "")
figured it out:
def remove_specialchr(string):
unwanted_specialchr = [',', '.', '"', '\'', ':',]
for chr in string:
if chr in unwanted_specialchr:
string = string.replace(chr, '')
return string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With