如果我有一个字符串列表,例如:
[("aaaa8"),("bb8"),("ccc8"),("dddddd8")...]
我应该怎么做才能去掉每个字符串中的所有 8
?我尝试在 for 循环中使用 strip
或 replace
但它不像在普通字符串中那样工作(不在列表中)。有人有什么建议吗?
最佳答案
试试这个:
lst = [("aaaa8"),("bb8"),("ccc8"),("dddddd8")]
print([s.strip('8') for s in lst]) # remove the 8 from the string borders
print([s.replace('8', '') for s in lst]) # remove all the 8s
关于python - 删除字符串列表中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8282553/