我有这个变量:
Words = ["Hi",".","how","are","you","?","I","feel","like","I","could",",","do","better"]
从这里我想要一个找到所有标点符号的变量,并将其放入列表中。像这样:
Punctuations = [".","?",","]
答案 0 :(得分:1)
您可以使用string.punctuation
来识别标点符号:
from string import punctuation
punctuations = [w for w in words if w in punctuation]
答案 1 :(得分:0)
使用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) # ['.', '?', ',']