0
我有這個變量的標點符號:找出所有的句子已經投入列表
Words = ["Hi",".","how","are","you","?","I","feel","like","I","could",",","do","better"]
從這個我想是找出所有的標點,並把它變成一個列表,以及一個變量。就像這樣:
Punctuations = [".","?",","]
我有這個變量的標點符號:找出所有的句子已經投入列表
Words = ["Hi",".","how","are","you","?","I","feel","like","I","could",",","do","better"]
從這個我想是找出所有的標點,並把它變成一個列表,以及一個變量。就像這樣:
Punctuations = [".","?",","]
您可以使用string.punctuation
識別標點符號:
from string import punctuation
punctuations = [w for w in words if w in punctuation]
使用re.findall
功能的解決方案:
import re
Words = ["Hi",".","how","are","you","?","I","feel","like","I","could",",","do","better"]
Punctuations = re.findall("[^\w\s]+", ''.join(Words))
print(Punctuations) # ['.', '?', ',']
有很多方法可以做到這一點,你做任何嘗試? –
我使用了string.punctuation方法 –