Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #4140
| Path | csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Michel <michel@domain.invalid> |
| Newsgroups | fr.comp.lang.python |
| Subject | Re: Tricher au scrabble... |
| Date | Sat, 02 Dec 2023 03:48:09 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 42 |
| Message-ID | <874jh1tlp1.fsf@gnus.org> (permalink) |
| References | <uk4fm4$852n$1@dont-email.me> <recherche-20231128131821@ram.dialup.fu-berlin.de> <uk51rm$auel$2@dont-email.me> <656a1a3b$0$10088$426a74cc@news.free.fr> <656a1e57$0$10088$426a74cc@news.free.fr> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | quoted-printable |
| Injection-Info | dont-email.me; posting-host="dca59e199930798328945c9eb8276c3d"; logging-data="2218323"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2PNmyNGgXraqn5lUnBppL" |
| User-Agent | Gnus |
| Cancel-Lock | sha1:b4E3M4EH7tU5RCChsY5EpA3bIJM= sha1:sLotOoJ1UrHGFY/k0kdrN8aq8Q4= |
| Mail-Copies-To | never |
| Xref | csiph.com fr.comp.lang.python:4140 |
Show key headers only | View raw
Le 1 décembre 2023 yves a écrit :
> dictionnaire = "/usr/share/dict/french"
> with open(dictionnaire) as f:
> resultat = [mot.rstrip() for mot in f.readlines() if
> sorted(mot.rstrip()) == sorted("acenrt")]
Pour les anagrammes c'est bon mais pour le scrabble on peut avoir des
lettres qui ne seraient pas utilisées et donc cet algo ne marcherait pas.
> 0.4 secondes sur mon ordi, quand même.
Sur le mien 0.280. Mais en reprenant le même principe que pour le
scrabble, en chargeant le fichier dans une array par longueur de mot,
j'obtiens 0.170.
fichier = "/usr/share/dict/french"
# on suppose que les mots font 27 caractères maxi
# (désinstitutionnalisassions)
MAX = 27
def charge_dico():
dictionnaire = [[] for i in range(MAX + 1)]
with open(fichier, 'r') as fp:
while line := fp.readline().rstrip():
dictionnaire[len(line)].append(line)
return dictionnaire
def recherche(lettres, dictionnaire):
resultat = [mot for mot in dictionnaire[len(lettres)]
if sorted(mot) == sorted(lettres)]
return resultat
tests = ['acenrt']
dictionnaire = charge_dico()
for lettres in tests:
print(lettres, ':', recherche(lettres, dictionnaire))
Back to fr.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Tricher au scrabble... Dominique <dominique.sextant@orange.fr.invalid> - 2023-11-28 11:33 +0100
Re: Tricher au scrabble... Dominique <dominique.sextant@orange.fr.invalid> - 2023-11-28 16:39 +0100
Re: Tricher au scrabble... Dominique <dominique.sextant@orange.fr.invalid> - 2023-11-28 16:43 +0100
Re: Tricher au scrabble... yves <yves@free.invalid> - 2023-12-01 17:39 +0000
Re: Tricher au scrabble... yves <yves@free.invalid> - 2023-12-01 17:56 +0000
Re: Tricher au scrabble... Michel <michel@domain.invalid> - 2023-12-02 03:48 +0100
Re: Tricher au scrabble... yves <yves@free.invalid> - 2023-12-06 22:22 +0000
Re: Tricher au scrabble... Michel <michel@domain.invalid> - 2023-12-07 10:28 +0100
Re: Tricher au scrabble... Thierry Pinelli <olmia2b+news@gmail.com> - 2023-12-07 16:35 +0100
Re: Tricher au scrabble... Thierry Pinelli <olmia2b+news@gmail.com> - 2023-12-07 17:52 +0100
Re: Tricher au scrabble... yves <yves@free.invalid> - 2023-12-07 18:00 +0000
Re: Tricher au scrabble... yves <yves@free.invalid> - 2023-12-07 18:07 +0000
Re: Tricher au scrabble... yves <yves@free.invalid> - 2023-11-28 16:05 +0000
Re: Tricher au scrabble... yves <yves@free.invalid> - 2023-11-28 16:17 +0000
Re: Tricher au scrabble... Dominique <dominique.sextant@orange.fr.invalid> - 2023-11-29 05:55 +0100
Re: Tricher au scrabble... yves <yves@free.invalid> - 2023-11-28 20:16 +0000
Re: Tricher au scrabble... Michel <michel@domain.invalid> - 2023-11-28 17:52 +0100
Re: Tricher au scrabble... Dominique <dominique.sextant@orange.fr.invalid> - 2023-11-29 05:57 +0100
Re: Tricher au scrabble... Michel <michel@domain.invalid> - 2023-11-28 19:23 +0100
csiph-web