You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

06-top-words.py 731 B

5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
5 年之前
12345678910111213141516171819202122232425262728293031323334353637
  1. # On veut obtenir la fréquence de chaque mot
  2. def get_freq(nom_fich):
  3. fich=open(nom_fich)
  4. contenu=fich.read()
  5. liste_frag=contenu.split() # coupe sur 'espace' et \
  6. liste_mot=list()
  7. for fragment in liste_frag:
  8. fragment_min=fragment.lower()
  9. frag_clean=clean(fragment_min)
  10. liste_mot.append(frag_clean)
  11. return liste_mot
  12. def clean(fragment):
  13. result=""
  14. for c in fragment:
  15. if c.isalpha():
  16. result+=c
  17. return result
  18. def tri(d):
  19. list_tuples=list()
  20. for clé, valeur in d.items():
  21. list_tuples.append((valeur, clé))
  22. list_tuples.sort(reverse=True)
  23. print(list_tuples)
  24. return d
  25. nom_fich="ruffin.txt"
  26. f=get_freq(nom_fich)
  27. print(f)