擅长:python、mysql、java
<p>我喜欢使用集合模块。这对我有用。在</p>
<pre><code>from collections import defaultdict
def HASHcount(file_to_open, lst):
with open(file_to_open) as my_file:
my_dict= defaultdict(int)
for line in my_file:
line = line.split('|||')
txt = line[4].strip(" ")
if txt in lst:
my_dict[txt] += 1
return my_dict
</code></pre>