Strumenti Utente

Strumenti Sito


lunghezza_delle_parole_grafiche

Questa è una vecchia versione del documento!


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+.5 for i in set_l], set_l, size='small')
plt.show()

Dovrebbe prodursi un grafico di questo tipo:

lunghezza_delle_parole_grafiche.1635170906.txt.gz · Ultima modifica: 2021/10/25 14:08 da 65.21.180.48