Python-删除一个或多个单词末尾和开头的标点符号

Shr*_*rmn -1 python algorithm

我想知道如何删除一个或多个单词末尾和开头的标点符号。如果单词之间有标点符号,我们不会删除。

例如

输入:

word = "!.test-one,-"

输出:

word = "test-one"

Eps*_*i95 6

使用strip

>>> import string
>>> word = "!.test-one,-"
>>> word.strip(string.punctuation)
'test-one'
Run Code Online (Sandbox Code Playgroud)