Build a Python Wordle Helper. A little creative Python code can help… | by John Clark Craig | Jan, 2022

A little creative Python code can help you whittle down the list of possible 5-letter Wordle words as you play!

John Clark Craig
January 26, 2022 Wordle solved using Python clues
Photo by Towfiqu barbhuiya on Unsplash
# whelper.pyuse_bigger_list = Falseguess_words = "adieu tears canoe black"   
hits_misses = "y.... ..g.. yy... ..ggg"
# Load the list of words
if use_bigger_list:
with open("word_list_bigger.txt") as f:
words = f.read().strip().split()
else:
with open("word_list.txt") as f:
words = f.read().strip().split()
# Process the guesses and scores into lists
guess = guess_words.lower().strip().split()
score = hits_misses.lower().strip().split()
# Get a nogo list of letters not in the word
nogo = []
for g, s in zip(guess, score):
for i in range(5):
if s[i] == ".":
nogo.append(g[i])
# Remove all words with nogo letters
for n in nogo:
for w in reversed(words):
if n in w:
words.remove(w)
# Get a list of all exact (green) letters
green = ["-", "-", "-", "-", "-"]
for g, s in zip(guess, score):
for i in range(5):
if s[i] == "g":
green[i] = g[i]
# Remove all words missing green matches
for i, letter in enumerate(green):
if letter != "-":
for w in reversed(words):
if letter != w[i]:
words.remove(w)
# Get a list of all non-exact (yellow) letters
yellow = ["-", "-", "-", "-", "-"]
for g, s in zip(guess, score):
for i in range(5):
if s[i] == "y":
yellow[i] = g[i]
# Remove all words missing nearby matches
for i, letter in enumerate(yellow):
if letter != "-":
for w in reversed(words):
if letter == w[i] or letter not in w:
words.remove(w)
# Output words that can still work (max 100)
print()
for i in range(100):
if i >= len(words):
break
if (i + 1) % 10:
print(words[i], end=" ")
else:
print(words[i])
if i == 99:
print("...there are more than 100 words")
break
print()
Photo by Adi Goldstein on Unsplash
words = ["one", "two", "two", "three"]# for x in words:
# if x == "two":
# words.remove(x)
# print(words) # ['one', 'two', 'three']
for x in reversed(words):
if x == "two":
words.remove(x)
print(words) # ['one', 'three']
Courtesy of Jesse Martini on Unsplash

Leave a Comment