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) if i <= ord("Z") or i >= ord("a")}
- count_dict_num = {chr(i):0 for i in range(ord("0"),ord("9")+1)}
- count_dict.update(count_dict_num)
- with open("eng2.txt","r",encoding="utf-8") as t:
- txt = t.readlines()
- for sentence in range(len(txt)):
- txt[sentence] = txt[sentence].replace('\n', '').replace(' ','')
- for c in txt[sentence]:
- if not c in count_dict:
- count_dict[c] = 1
- else:
- count_dict[c] += 1
- plt.bar(count_dict.keys(), count_dict.values())
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement