I have a list on which I try to remove special chars using a loop. When I\'ve tried to remove those special chars without a loop, it worked. But with a loop didn\'t work, bu
You can do this using a list comprehension, you mean something like this?
>>> import re >>> x = [ '[1]', '[2]' ] >>> [re.sub(r'\W', '', i) for i in x] ['1', '2']
The token \W matches any non-word character.
\W