【问题标题】:How to remove escape-sequence from list elements in python? [closed]如何从python中的列表元素中删除转义序列? [关闭]
【发布时间】:2019-09-06 11:32:43
【问题描述】:

我有一个列表,列表的每个元素都包含一个转义序列“\n”..如何从元素中删除这些“\n”?

【问题讨论】:

标签: python escaping


【解决方案1】:

像这样:

lst = ['\n', 'hello\n']
new_lst = [entry.replace('\n','') for entry in lst]
print(new_lst) #['', 'hello']

【讨论】:

  • 它不工作.. 是否有任何库或内置函数可用于此??
  • 嗯,你需要 Python 来运行它。除此之外,什么都不需要。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-17
  • 2021-03-10
  • 1970-01-01
  • 2013-01-13
相关资源
最近更新 更多