単語のリストを含むファイルがあり、1行ずつ単語を読んでいる単語を探しています。common_wordsファイルのサンプルは次のようになります。
yourself
yourselves
z
zero
リストは辞書式順序で並べ替えられます。
def isCommonWord(word):
commonWordList = open("common_words", 'r')
commonWord = commonWordList.readline()
commonWord = commonWord.rstrip("\n")
while commonWord <= word:
if commonWord == word:
return True
commonWord = commonWordList.readline()
commonWord = commonWord.rstrip("\n")
return False
if isCommonWord("zeros"):
print "true"
else:
print "false"
現在、この関数は無限ループに入っています。私はこれがどのように起こっているのか分かりません。どんな助けでも大歓迎です。「ゼロ」以外の他の変数を試してみると、完全に正常に機能します。「ゼロ」だけで私は問題に直面しています。お時間をいただきありがとうございます。