Guest User

Untitled

a guest
May 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. def find_most_frequent(text):
  2.  
  3. import math
  4.  
  5. dict_for_words_and_numbers_of_words = {}
  6. list_for_dict_values = []
  7. list_for_dict_keys = []
  8.  
  9. text = text.lower()
  10.  
  11. for i in text:
  12. if not str(i).isalpha() and i != ' ':
  13. text = text.replace(i, '')
  14.  
  15. text = text.split()
  16.  
  17. for word in text:
  18. if word in dict_for_words_and_numbers_of_words:
  19. dict_for_words_and_numbers_of_words[word] += 1
  20. else:
  21. dict_for_words_and_numbers_of_words[word] = 1
  22.  
  23. for i in dict_for_words_and_numbers_of_words.values():
  24. list_for_dict_values.append(i)
  25.  
  26. for i in dict_for_words_and_numbers_of_words.keys():
  27. list_for_dict_keys.append(i)
  28.  
  29. kk = []
  30. for i in range((len(list_for_dict_values))):
  31. if list_for_dict_values[i] == max(list_for_dict_values):
  32. kk.append(list_for_dict_keys[i])
  33.  
  34. return print(kk)
  35.  
  36. find_most_frequent('my name is andrew Is my best name')
Add Comment
Please, Sign In to add comment