Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import matplotlib
- import matplotlib.pyplot as plt
- count_dict = {chr(i):0 for i in range(ord("A"),ord("Z")+1)}
- 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"]
- aiustr = ""
- def looper(func):
- def new_func(*args,**kwargs):
- with open("kasu2.txt","r",encoding="utf-8") as t:
- txt = t.readlines()
- for sentence in range(len(txt)):
- for word in range(len(txt[sentence])):
- alpha = txt[sentence][word] # Original character
- func(alpha)
- return 0
- return new_func
- @looper
- def word_count(alpha=0):
- alpha = ord(alpha.upper())
- try:
- if alpha >= ord("A") and alpha <= ord("Z"):
- count_dict[chr(alpha)] += 1
- except KeyError:
- pass
- @looper
- def change_char(alpha=0):
- global aiustr
- sort_list = sorted(count_dict.items(), key=lambda x: x[1],reverse=True)
- no = 0
- if alpha == " ":
- aiustr += " "
- return 0
- for i in sort_list:
- if i[0] == alpha.upper():
- aiustr += freq_char[no]
- no += 1
- if __name__ == "__main__":
- word_count()
- change_char()
- print(aiustr)
- # plt.bar(count_dict.keys(), count_dict.values())
- # plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement