3 ms·
# Written at an ungodly hour may be bug riddled enjoy def is_valid(word, conditions, final_guess): """ Checks if it is a valid guess - word => The
by accurrent 5y ago
# Written at an ungodly hour may be bug riddled enjoy
def is_valid(word, conditions, final_guess):
"""
Checks if it is a valid guess
- word => The word in question
- conditions => The conditions. A string of 5 characters. '-' means a grey cell, 'G' is a green cell and 'y' is a yellow cell.
- final_guess => The final guess.
"""
if len(word) != 5:
return False
for i in range(5):
if conditions[i] == "G":
if word[i] != final_guess[i]:
return False
if conditions[i] == "-":
if word[i] in final_guess:
return False
if conditions[i] == "y":
if word[i] not in final_guess[:i] and word[i] not in final_guess[i+1:] or word[i] == final_guess[i]:
return False
return True
## How to use
with open("/usr/share/dict/words") as f:
for line in f:
word = line.strip()
## Replace with appropiate parameters.
if not is_valid(word, "--yy-", "piano"):
continue
print(word)