這是我有一個字符串列表:Python的分裂標點符號,但仍然包括它
[
['It', 'was', 'the', 'besst', 'of', 'times,'],
['it', 'was', 'teh', 'worst', 'of', 'times']
]
我需要times,
分裂標點符號,是'times',','
或另一個例子,如果我有Why?!?
我會需要它是'Why','?!?'
import string
def punctuation(string):
for word in string:
if word contains (string.punctuation):
word.split()
我知道它根本不是python語言!但這就是我想要的。
你的意思是你要來標記?因此,如果您還有「$ 3.88」或「:」字符串中的尾隨單詞,您是否也想將它們分開,並保留分隔符? – Tom
我之前沒有使用過tokenize函數。那會做什麼? – user2553807
沒有一個。但是有一個包http://nltk.org/api/nltk.tokenize.html。 – Tom