-
lines_count = 0
-
words_count = 0
-
chars_count = 0
-
words_dict = {}
-
lines_list = []
-
c1 = ['!', '?', ';', '.', ',']
-
all_line = ''
-
import collections
-
-
with open('c:\invalid.txt', 'r') as f:
-
for line in f:
-
line = line.strip('\n')
-
lines_count = lines_count + 1
-
all_line=all_line+line.lower()
-
# print line
-
#print all_line
-
for i in c1:
-
all_line=all_line.replace(i,' ')
-
# print all_line
-
str1=all_line.split(' ')
-
for i in str1:
-
if i not in words_dict:
-
words_dict[i] = 1
-
else:
-
words_dict[i] = words_dict[i] + 1
-
-
c1=words_dict.items()
-
c2=[]
-
for i in c1:
-
c2.append((i[1],i[0]))
-
d2={}
-
d2={}
-
for i in c2:
-
d2[i[0]]=i[1]
-
-
-
def mySort(a):
-
lo = len(a) - 1
-
i = 0
-
while i < lo + 1:
-
j = lo
-
while j >= i:
-
if (a[j - 1] > a[j]):
-
a[j], a[j - 1] = a[j - 1], a[j]
-
j = j - 1
-
i = i + 1
-
-
-
if __name__ == '__main__':
-
for i in sorted(d2.keys()):
-
print d2[i], ':', i