python - Replace in strings of list -
i can utilize re.sub
in single string this:
>>> = "ajhga':&+?%" >>> = re.sub('[.!,;+?&:%]', '', a) >>> "ajhga'"
if utilize on list of strings not getting result. doing is:
>>> = ["abcd:+;", "(l&'kka)"] >>> x in a: ... x = re.sub('[\(\)&\':+]', '', x) ... >>> ['abcd:+;', "(l&'kka)"]
how can strip expressions strings in list?
for index,x in enumerate(a): a[index] = re.sub('[\(\)&\':+]', '', x)
your changing value not updating list. enumerate function homecoming tuple (index,value)
each item of list
python string
No comments:
Post a Comment