Advertisement
Guest User

Untitled

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