I am working on a problem from a book, Think Python, which I thought would be fairly easy. The problem is:<div><br></div><div><div>Exercise 11.1. Write a function that reads the words in words.txt and stores them as keys in a</div>
<div>dictionary. It doesn’t matter what the values are. Then you can use the in operator as a fast way to</div><div>check whether a string is in the dictionary.</div></div><div><br></div><div>Note: words.txt is just a huge word list file if anyone is confused about that</div>
<div><br></div><div>Here is my failed solution:</div><div><br></div><div><div>def tester():</div><div>    fin = open(&#39;/home/moheem/Documents/words.txt&#39;, &#39;r&#39;)</div><div>    value = 0</div><div>    wordDict = dict()</div>
<div>    for word in fin:</div><div>        wordDict[word] = value</div><div>        value = value + 1</div><div>        </div><div>    fin.close()</div></div><div><br></div><div>There seems to be a logical error. That is, when I check a key, i.e. one of the words from the file, is in the dictionary, I get false. (To check, I use: &#39;aa&#39; in wordDict). I think the problem is that the key does not actually get placed in the dictionary, but the question is why?</div>