From 9c9439b39be5b4c32f1d8355dec117f8d1498b16 Mon Sep 17 00:00:00 2001 From: Antoine Van Elstraete Date: Tue, 25 Jan 2022 13:13:38 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20de=20"resolv=5Fpattern()"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wgamesolv.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wgamesolv.py b/wgamesolv.py index 404434d..c23b866 100755 --- a/wgamesolv.py +++ b/wgamesolv.py @@ -57,10 +57,12 @@ def resolv_len(liste, lenght): def resolv_pattern(liste, pattern): # Pattern : élimination des mots ne satisfaisant pas la pattern - pattern_dict = {} + pattern_dict, not_pattern_dict = {}, {} for lettre in pattern: - if lettre != ".": + if lettre != "." and lettre.isupper(): pattern_dict.update({pattern.index(lettre): lettre}) + if lettre != "." and lettre.islower(): + not_pattern_dict.update({pattern.index(lettre): lettre.upper()}) MotsOK, MotsKO = [], [] for mot in liste: for key in pattern_dict: @@ -68,6 +70,10 @@ def resolv_pattern(liste, pattern): MotsOK.append(mot) else: MotsKO.append(mot) + for key in not_pattern_dict: + if mot[key] == not_pattern_dict[key]: + MotsKO.append(mot) + MotsKO = set(MotsKO) liste = [mot for mot in MotsOK if mot not in MotsKO] liste = list(set(liste)) return liste