Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 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) if i <= ord("Z") or i >= ord("a")}
  6. count_dict_num = {chr(i):0 for i in range(ord("0"),ord("9")+1)}
  7. count_dict.update(count_dict_num)
  8.  
  9. with open("eng2.txt","r",encoding="utf-8") as t:
  10. txt = t.readlines()
  11. for sentence in range(len(txt)):
  12. txt[sentence] = txt[sentence].replace('\n', '').replace(' ','')
  13. for c in txt[sentence]:
  14. if not c in count_dict:
  15. count_dict[c] = 1
  16. else:
  17. count_dict[c] += 1
  18.  
  19. plt.bar(count_dict.keys(), count_dict.values())
  20. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement