Nettoyage

This commit is contained in:
Antoine Van Elstraete 2022-01-24 22:22:40 +01:00
parent e4b517168a
commit fc93178303

View File

@ -6,12 +6,12 @@ import argparse
def load_dict(dict_file): def load_dict(dict_file):
try : try:
with open(dict_file, "r") as dico: with open(dict_file, "r") as dico:
liste = json.load(dico) liste = json.load(dico)
return liste return liste
except: except Exception as error:
print("Impossible d'ouvrir le fichier" + fp) print(f"Impossible d'ouvrir le fichier {dict_file} : {error}")
exit(2) exit(2)
@ -20,13 +20,14 @@ def noDouble(mots):
ndList = [] ndList = []
for mot in mots: for mot in mots:
llist = [] llist = []
for l in mot: for lettre in mot:
if not l in llist: if lettre not in llist:
llist.append(l) llist.append(lettre)
if len(mot) == len(llist): if len(mot) == len(llist):
ndList.append(mot) ndList.append(mot)
return(ndList) return(ndList)
def firstTryFilter(mots, max_mots): def firstTryFilter(mots, max_mots):
''' '''
First Try : sélectionne des mots ayant des chances de valider ou invalider First Try : sélectionne des mots ayant des chances de valider ou invalider
@ -71,19 +72,12 @@ def resolv_pattern(liste, pattern):
liste = list(set(liste)) liste = list(set(liste))
return liste return liste
#if pattern:
# patternCount = len(pattern) - pattern.count(".")
# for mot in goodLen:
# patternEval = 0
# for l in range(len(mot)):
# if mot[l] == pattern[l]:
# patternEval += 1
# if patternEval == patternCount :
# patternFilter.append(mot)
#
def resolv_kl(liste, lettres): def resolv_kl(liste, lettres):
# Known Letters : élimination des mots ne comprenant pas les lettres validées (hors pattern) '''
Known Letters : élimination des mots ne comprenant pas
les lettres validées (hors pattern)
'''
lettres = list(set(list(lettres))) lettres = list(set(list(lettres)))
MotsRestants = [] MotsRestants = []
for mot in liste: for mot in liste:
@ -93,7 +87,10 @@ def resolv_kl(liste, lettres):
def resolv_bl(liste, lettres): def resolv_bl(liste, lettres):
# Bad Letters : élimination des mots contenant des lettres invalidées (hors pattern) '''
Bad Letters : élimination des mots contenant
des lettres invalidées (hors pattern)
'''
lettres = list(set(list(lettres))) lettres = list(set(list(lettres)))
MotsSuppr = [] MotsSuppr = []
for mot in liste: for mot in liste:
@ -103,7 +100,7 @@ def resolv_bl(liste, lettres):
for mot in MotsSuppr: for mot in MotsSuppr:
try: try:
liste.pop(liste.index(mot)) liste.pop(liste.index(mot))
except: except ValueError:
pass pass
return liste return liste
@ -167,11 +164,11 @@ if __name__ == "__main__":
) )
args = parser.parse_args() args = parser.parse_args()
if args.pattern and args.nbLetters and len(args.pattern) != args.nbLetters: if args.pattern and args.nbLetters and len(args.pattern) != args.nbLetters:
print("Tu as merdé ta pattern petit scarabé !") print("Tu as merdé ta pattern petit scarabé !")
exit(2) exit(2)
liste = load_dict(args.dictionary) liste = load_dict(args.dictionary)
liste = resolv_len(liste, args.nbLetters) liste = resolv_len(liste, args.nbLetters)
liste = resolv_fl(liste, args.firstLetter) liste = resolv_fl(liste, args.firstLetter)