I'm trying to remove or ignore the '
symbol (Apostrophe) within a list of strings. I don't know if my for loop is just plain wrong or what:
n = ["a", "a's", "aa's"] #example list
for i in n:
i.strip("'")
I'm trying to remove or ignore the '
symbol (Apostrophe) within a list of strings. I don't know if my for loop is just plain wrong or what:
n = ["a", "a's", "aa's"] #example list
for i in n:
i.strip("'")
strip
won't work here use replace
,
In [9]: [i.replace("'",'') for i in lst]
Out[9]: ['a', 'as', 'aas']
Two problems here.
strip
doesn't work in the middle of the string, you have to use `replace("'", "")i.strip(...)
did what you want, it would not change i
. It would just produce a new string. So, you have to store that string. Sum up, try something like
n = [i.replace("'", "") for i in n]