Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. import re
  2. d = {}
  3. f = open("lorem.txt")
  4. s = f.read()
  5. s = re.sub(r'[^\w\s]','',s)
  6. a = s.lower().split()
  7. dictionary = {}
  8. for word in a:
  9.     if word in dictionary.keys():
  10.         dictionary[word] += 1
  11.     else:
  12.         dictionary[word] = 1
  13. print(dictionary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement