如何从python列表中的字符串项目中删除\\ n?

问题描述 投票:0回答:1

我有一个存储\ n值的列表。如何以编程方式快速删除它们?

myList = ['My new title    ', '\\nTest\\nSent from my mobile device\\n', 'Test\\n\\nSent from my mobile device\\n']

到目前为止,我已经尝试过:

myNewList = ([s.replace('\\n', '') for s in myList])

但这将我的单词拆分为单个字母-使它们列出项目。有人可以帮忙吗?提前致谢!

python regex string
1个回答
0
投票

这是吗?

myList = ['My new title    ', '\\nTest\\nSent from my mobile device\\n', 'Test\\n\\nSent from my mobile device\\n']
myNewList = [s.replace('\\n','') for s in myList]
print(myNewList)
© www.soinside.com 2019 - 2024. All rights reserved.