from unidecode import unidecode
from matplotlib.pyplot import bar,show,xticks

def create_histo(dico):
    xticks(rotation = 'vertical')
    bar(list(dico.keys()), dico.values(), color='g')
    show()

alphabet = dict()
nb_lettres = 0

with open('mots.txt','r',encoding='utf8') as Fichier:
    lines = Fichier.readlines()
    for l in lines:
        ligne = unidecode(l).replace('\n','').upper()
        for lettre in ligne:
            if lettre != "'" and lettre != '-' and lettre != ' ':
                nb_lettres += 1
                if lettre in alphabet:
                    alphabet[lettre] += 1
                else:
                    alphabet[lettre] = 1
                
frequences = dict()

"""
for key, values in alphabet.items():
"""
for c in sorted(alphabet.items() , key = lambda t: t[0]):
    frequences[c[0]] = alphabet[c[0]] / nb_lettres
  

for c in range(65,91):
    print('{} : {}%'.format(chr(c),round(frequences[chr(c)]*100,2)))
    
create_histo(frequences)