我正在爲輸入單詞搜索文本文件。但是,我只是想在文字「開始」之後搜索文件中的文本。 「開始」之前的第一個二十幾個應該被忽略。我知道如何查找「開始」,但不知道如何在遇到「開始」時搜索文件的其餘部分。我將不勝感激任何指導!如何在發現一個單詞時遍歷文件
這是我到目前爲止有:
file = open("EnglishWords.txt", "r")
print("***** Anagram Finder *****")
word = input("Enter a word: ")
for line in file:
if "START" in line:
if word in line:
print("Yes, ", word, " is in the file.", sep="")
else:
print("Sorry, ", word, " is not in the file.", sep="")
file.close()
這裏是文本文件的樣本:
The name of Princeton University or Princeton may not be
used in advertising or publicity pertaining to
distribution of the software and/or database. Title to
copyright in this software, database and any associated
documentation shall at all times remain with Princeton
University and LICENSEE agrees to preserve same.
START
clobber
transversalis
squinter
cunner
damson
extrovertive
absorptive
你嘗試過這麼遠嗎? – ILostMySpoon
迭代如何?逐詞地?逐行?基本上,你閱讀,直到你找到開始,然後繼續閱讀。你如何繼續取決於你如何開始。也就是說,你到目前爲止有什麼? – alexis
你可以[編輯你的問題](https://stackoverflow.com/posts/44568438/edit)包含你的文本文件的樣本以及你試圖在其中找到的東西。 –