在第 2 行中,您将整个列表转换为字符串,包括逗号和引号。相反,我会尝试将它们全部放入一个字符串中,其中包含所有句子中的单词,但没有引号或逗号。我会做这样的事情来获得“strsent”:
# declare your sentences list here
strsent = ' '.join(sentences)
split = strsent.split()
# the rest of your code after line 4 would be the same
如果你真的想简化所有代码,你可以这样做:
sentences = [] # add your own sentences here
strsent = ' '.join(sentences)
split = strsent.split()
unique_words = sorted(set(split))
print(unique_words)
如果这有帮助或者您还有其他问题,请告诉我!