Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- try:
- f = open(sys.argv[1])
- except:
- input_line = input()
- if os.path.exists(input_line):
- f = open(input_line)
- else:
- print("File not exists")
- sys.exit(1)
- mydict = {"":0}
- i=0
- for line in f:
- words = line.replace(",", " ").replace('"',' ').split()
- for word in words:
- word = word.lower()
- i += 1
- if(word in mydict.keys()):
- value = mydict[word]
- value += 1
- mydict.pop(word)
- else:
- value = 1
- mydict[word] = value
- print("Number of words: " + str(i))
- i=0
- for k, v in sorted(mydict.items(), key=lambda x: -x[1]):
- if(i >= 20):
- break
- print(str(k) + ": " + str(v))
- i += 1
- f.close()
Add Comment
Please, Sign In to add comment