Strumenti Utente

Strumenti Sito


lunghezza_delle_parole_grafiche

Lunghezza delle parole grafiche

Il codice seguente crea il grafico della frequenza delle parole grafiche di una determinata lunghezza in Pinocchio.

lunghezza.py
import re
import matplotlib.pyplot as plt
f=open('testi/collodi_pinocchio.txt', mode='r', encoding='iso-8859-1')
testo=f.read()
testo=testo[1704:]
testo=re.sub("'","' ", testo)
testo=re.sub('[\.,;:\-?!]{1}','',testo)
testo=testo.lower()
testo=testo.split()
l=[len(i) for i in testo]
set_l=list(set(l))
set_l.sort()
freq_l=[l.count(i) for i in set_l]
plt.bar(set_l,freq_l)
plt.xticks([i for i in set_l], set_l, size='small')
plt.show()

Dovrebbe prodursi un grafico di questo tipo:

lunghezza_delle_parole_grafiche.txt · Ultima modifica: 2021/10/29 21:22 da deleteme