import re f = open('testi/collodi_pinocchio.txt', mode='r', encoding='iso-8859-1') testo = f.read() testo=file.read() testo=testo[1704:] testo=re.sub("'","' ", testo) testo=re.sub('[,;:\-?!]{1}',' \g<0>',testo) testo=re.sub('([^\.]+)(\.)','\g<1> \g<2>',testo) testo=testo.lower() testo=testo.split()