Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import matplotlib
  3. import matplotlib.pyplot as plt
  4.  
  5. count_dict = {chr(i):0 for i in range(ord("A"),ord("Z")+1)}
  6. freq_char = ["e","a","t","i","o","s","n","r","h","l","d","c","u","m","p","f","g","y","w","b","v","k","j","x","q","z"]
  7. aiustr = ""
  8.  
  9. def looper(func):
  10. def new_func(*args,**kwargs):
  11. with open("kasu2.txt","r",encoding="utf-8") as t:
  12. txt = t.readlines()
  13. for sentence in range(len(txt)):
  14. for word in range(len(txt[sentence])):
  15. alpha = txt[sentence][word] # Original character
  16. func(alpha)
  17. return 0
  18. return new_func
  19.  
  20. @looper
  21. def word_count(alpha=0):
  22. alpha = ord(alpha.upper())
  23. try:
  24. if alpha >= ord("A") and alpha <= ord("Z"):
  25. count_dict[chr(alpha)] += 1
  26. except KeyError:
  27. pass
  28.  
  29. @looper
  30. def change_char(alpha=0):
  31. global aiustr
  32. sort_list = sorted(count_dict.items(), key=lambda x: x[1],reverse=True)
  33. no = 0
  34.  
  35. if alpha == " ":
  36. aiustr += " "
  37. return 0
  38.  
  39. for i in sort_list:
  40. if i[0] == alpha.upper():
  41. aiustr += freq_char[no]
  42. no += 1
  43.  
  44. if __name__ == "__main__":
  45. word_count()
  46. change_char()
  47. print(aiustr)
  48. # plt.bar(count_dict.keys(), count_dict.values())
  49. # plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement