我有各种单词列表,其中很多都是嘈杂的。我所说的嘈杂是指它以一些非字母字符开头,例如 ' "'、' - '。例如:"thisword, -thisword , -"this word, .thisword 并且可以是其他几个。
就像我们可以使用
删除 asciifrom string import ascii letter
string.lstrip(ascii_letters)
在python中有没有类似的方法可以不使用正则表达式来处理non_ascii?
谢谢!
请您参考如下方法:
你为什么不使用 string.puctuation
>>> from string import punctuation
>>> "-asdf".lstrip(punctuation)
'asdf'
>>> "'asdf".lstrip(punctuation)
'asdf'
>>> '"asdf'.lstrip(punctuation)
'asdf'
>>> ',asdf'.lstrip(punctuation)
'asdf'
