擅长:python、mysql、java
<blockquote>
<p>This code is relying on the fact that Python considers an empty string, or '' to be a False, while a non-empty string is True</p>
</blockquote>
<pre><code>def make_dictionary(filename):
text = open(filename,'r').read()
wordfreq = {}
for word in text.strip().split('\n'):
for line in text:
if not line.strip():
continue
else:
wordfreq[word] = wordfreq.get(word, 0) +1
return wordfreq
</code></pre>