Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- def wordFreq(text):
- counts = dict()
- words = text.split()
- count = 0
- for word in words:
- if word in counts:
- counts[word]+=1
- else:
- counts[word]=1
- with open('words.txt','w') as fo:
- fo.write(json.dumps(counts))
- filename = input("Enter file to analyze: ")
- with open(filename, 'r') as fi:
- text = fi.read()
- wordFreq(text)
Add Comment
Please, Sign In to add comment