-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")
有人可以幫助我建立一個更好的解決方案/解決這一問題,以便它的工作原理?