Le mot le plus long en langue française est bien connu. C'est « anticonstitutionnellement ».
Nous allons répondre à ces questions hautement importantes.
#!/usr/bin/python
with open("liste.de.mots.francais.frgut.txt", "r") as infile:
for line in infile:
mot = line.strip("\n")
longueur = len(mot.decode('utf8'))
print longueur, mot
#!/bin/sh ./longueur_mot.py | sort -n
set style data histograms set style fill solid 1.00 border lt -1 #set boxwidth 2 absolute set boxwidth 2.6 relative set terminal svg size 600,400 dynamic enhanced fname 'arial' fsize 10 mousing name "histograms_2" butt solid set title "histogramme des tailles de mots" set output 'histogramme.svg' set xrange [1:25] plot "histogramme.dat"
#!/usr/bin/python
# -*- coding: utf-8 -*-
LISTE = "liste.de.mots.francais.frgut.txt"
#LISTE = "petite.liste.txt"
def canonicalise(lettre):
exceptions = {'A': 'a', u'à': 'a', u'â': 'a',
u'ç': 'c',
u'é': 'e', u'è': 'e', u'ê': 'e', u'ë': 'e',
u'î': 'i', u'ï': 'i',
u'ô': 'o',
u'ù': 'u', u'û': 'u'}
if lettre in exceptions:
lettre = exceptions[lettre]
return lettre
def decompose(mot):
decompte = dict()
for lettre in mot:
lettre = canonicalise(lettre)
try:
decompte[lettre] += 1
except KeyError:
decompte[lettre] = 1
# quelle lettre est la plus fréquente ?
max = 0
for lettre in decompte:
if decompte[lettre] > max:
max = decompte[lettre]
lettre_max = lettre
decompte['max'] = lettre_max
return decompte
dictionnaire = dict()
with open(LISTE, "r") as infile:
for line in infile:
mot = line.strip("\n").decode('utf8')
dictionnaire[mot] = decompose(mot)
lettres_max = dict()
for mot in dictionnaire:
decomp = dictionnaire[mot]
lettre_max = decomp['max']
occurence = decomp[lettre_max]
try:
lettre = lettres_max[lettre_max]
except KeyError:
lettre = {'occurence': 0, 'mot': list()}
if occurence > lettre['occurence']:
lettres_max[lettre_max] = {'occurence': occurence, 'mot': [mot]}
elif occurence == lettre['occurence']:
lettres_max[lettre_max]['mot'].append(mot)
for lettre in sorted(lettres_max):
res = lettres_max[lettre]
print lettre, res['occurence'],
for mot in res['mot']:
print mot,
print
print
#!/usr/bin/python
# -*- coding: utf-8 -*-
LISTE = "liste.de.mots.francais.frgut.txt"
#LISTE = "petite.liste.txt"
def canonicalise(lettre):
exceptions = {'A': 'a', u'à': 'a', u'â': 'a',
u'ç': 'c',
u'é': 'e', u'è': 'e', u'ê': 'e', u'ë': 'e',
u'î': 'i', u'ï': 'i',
u'ô': 'o',
u'ù': 'u', u'û': 'u'}
if lettre in exceptions:
lettre = exceptions[lettre]
voyelles = "aeiouy"
if lettre in voyelles:
lettre = "voyelle"
else:
lettre = "consonne"
return lettre
def decompose(mot):
decompte = {"consonne": 0, "voyelle": 0}
for lettre in mot:
lettre = canonicalise(lettre)
decompte[lettre] += 1
return decompte
dictionnaire = dict()
with open(LISTE, "r") as infile:
for line in infile:
mot = line.strip("\n").decode('utf8')
dictionnaire[mot] = decompose(mot)
max_voyelles = 0
max_taux_voyelles = 0.0
min_taux_voyelles = 1.0
max_consonnes = 0
for mot in sorted(dictionnaire):
decomp = dictionnaire[mot]
voyelles = decomp["voyelle"]
consonnes = decomp["consonne"]
if voyelles > max_voyelles:
max_voyelles = voyelles
max_voyelles_mot = mot
if consonnes > max_consonnes:
max_consonnes = consonnes
max_consonnes_mot = mot
taux_voyelles = (voyelles + 0.0) / len(mot)
if taux_voyelles > max_taux_voyelles:
max_taux_voyelles = taux_voyelles
max_taux_voyelles_mot = mot
if taux_voyelles < min_taux_voyelles:
min_taux_voyelles = taux_voyelles
min_taux_voyelles_mot = mot
print taux_voyelles
#print mot.encode("utf8"), voyelles, consonnes
print "voyelles", max_voyelles, max_voyelles_mot.encode("utf8")
print "consonnes", max_consonnes, max_consonnes_mot.encode("utf8")