Amélioration de "resolv_pattern()"
This commit is contained in:
parent
23c8f27def
commit
9c9439b39b
10
wgamesolv.py
10
wgamesolv.py
@ -57,10 +57,12 @@ def resolv_len(liste, lenght):
|
|||||||
|
|
||||||
def resolv_pattern(liste, pattern):
|
def resolv_pattern(liste, pattern):
|
||||||
# Pattern : élimination des mots ne satisfaisant pas la pattern
|
# Pattern : élimination des mots ne satisfaisant pas la pattern
|
||||||
pattern_dict = {}
|
pattern_dict, not_pattern_dict = {}, {}
|
||||||
for lettre in pattern:
|
for lettre in pattern:
|
||||||
if lettre != ".":
|
if lettre != "." and lettre.isupper():
|
||||||
pattern_dict.update({pattern.index(lettre): lettre})
|
pattern_dict.update({pattern.index(lettre): lettre})
|
||||||
|
if lettre != "." and lettre.islower():
|
||||||
|
not_pattern_dict.update({pattern.index(lettre): lettre.upper()})
|
||||||
MotsOK, MotsKO = [], []
|
MotsOK, MotsKO = [], []
|
||||||
for mot in liste:
|
for mot in liste:
|
||||||
for key in pattern_dict:
|
for key in pattern_dict:
|
||||||
@ -68,6 +70,10 @@ def resolv_pattern(liste, pattern):
|
|||||||
MotsOK.append(mot)
|
MotsOK.append(mot)
|
||||||
else:
|
else:
|
||||||
MotsKO.append(mot)
|
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 = [mot for mot in MotsOK if mot not in MotsKO]
|
||||||
liste = list(set(liste))
|
liste = list(set(liste))
|
||||||
return liste
|
return liste
|
||||||
|
Loading…
Reference in New Issue
Block a user