我想抓取构成口语中整个单词的文本组(由空格分隔的文本组被视为单词)。例如,当我想在文本文件中查找单词is时,即使该文件不包含单词 is ,也会检测到单词 s is ter 内的 is 。我对词法分析有所了解,但无法将其应用到我的项目中。有人可以提供这种情况的 python 代码吗?
这是我使用的代码,但它导致了上述问题。
words_to_find = ("test1", "test2", "test3")
line = 0
#User_Input.txt is a file saved in my computer which i used as the input of the system
with open("User_Input.txt", "r") as f:
txt = f.readline()
line += 1
for word in words_to_find:
if word in txt:
print(F"Word: '{word}' found at line {line}, "
F"pos: {txt.index(word)}")
FFIVE
噜噜哒
狐的传说
倚天杖
慕容森
相关分类