Python:删除软连字符

Mar*_*kF6 1 html python

在 html 文件中,我有包含软连字符的单词,例如

"Schilde rung"
repr(word) = "Schilde\\xc2\\xadrung"
Run Code Online (Sandbox Code Playgroud)

我怎样才能删除它们?

由于我的文件还包含变音符号和其他特殊字符,因此带有 printable 或 with 的解决方案words.decode('ascii', 'ignore')并不是很好......

我已经尝试过使用words.replace('\xc2\xad', ''); 但这没有用。

谢谢你的帮助 :)

Ric*_*dle 5

你不能replace按名单行事;您需要在列表中的每个成员上运行它:

words = ["Hello", "Schilde\xc2\xadrung"]
words = [word.replace('\xc2\xad', '') for word in words]
print repr(words)
# Prints ['Hello', 'Schilderung']
Run Code Online (Sandbox Code Playgroud)