I have a list of elements containing special characters. I want to convert the list to only alphanumeric characters. No special characters. my_list = ["on@3", "two#", "thre%e"]
my expected output is,
out_list = ["one","two","three"]
I cannot simply apply strip()
to these items, please help.
Here is another solution:
import re
my_list= ["on@3", "two#", "thre%e"]
print [re.sub('[^a-zA-Z0-9]+', '', _) for _ in my_list]
output:
['on3', 'two', 'three']
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