-
Notifications
You must be signed in to change notification settings - Fork 2
/
vocab_lists.py
32 lines (25 loc) · 981 Bytes
/
vocab_lists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#################===README===########################################
# #
# Run system as python vocab_lists.py filename_you_want_vocab #
# #
#####################################################################
import sys
fname = sys.argv[1]
global_dict={}
class LoadFile(object):
#Returns an iterator to iterate on...
def __init__(self, filename):
self.filename = filename
def __iter__(self):
for line in open(self.filename):
yield line.split()
sentences = LoadFile(fname)
for sentence in sentences:
for token in sentence:
token = token.lower()
if token in global_dict:
global_dict[token]+=1
else:
global_dict[token]=1
for key, value in sorted(global_dict.iteritems(), key=lambda(k,v): (v,k), reverse=True):
print("%s: %s" % (key, value))