I have a file with a list of words and I am trying to look for a word reading line by line. A sample of common_words file would be:
yourself
yourselves
z
zero
The list is lexicographically sorted.
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"
Now this function is getting into an infinite loop. I have no idea how this is happening. Any help will be greatly appreciated. If I try other variables besides "zeros" then it works perfectly fine. Only with the "zeros" I am facing trouble. Thank you for your time.
readlineeven after reaching the end of file.