Amélioration de "resolv_pattern()"

This commit is contained in:
Antoine Van Elstraete 2022-01-25 13:13:38 +01:00
parent 23c8f27def
commit 9c9439b39b
Signed by: AntoineVe
GPG Key ID: E36069A977E2A9ED

View File

@ -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