-1
我试图让我的程序通过输入句子(例如“你好!”) 并查看输入中的任何单词是否在列表中。 这里是迄今为止代码:Python如何检查单词是否在列表和输入中?
def findWholeWord(w):
return re.compile(r'\b({0})\b'.format(w), flags=re.IGNORECASE).search
i.upper() #i is the inputted variable as a string
WordsDocument = open('WordsDocument.txt').readlines()
for words in WordsDocument:
WordsList.append(words)
for word in i:
if findWholeWord(word) in WordsList:
print("Word Match")
有人可以帮助我建立一个更好的解决方案/解决这一问题,以便它的工作原理?