Create Wordle with Python

Seemant Singh
2 min readFeb 13, 2022

--

Photo by Annie Spratt on Unsplash

Started my Sunday morning with daily ritual of predicting today’s word on Wordle. I did succeed but was confused with today’s word, so I did what a common bad friend will do, I took a screenshot and sent it to my friend asking if it is a real word. Unaware of if she had completed her ritual today i started panicking. That’s when Python came to my rescue and i created a Wordle clone.

If you don’t know the rules please first visit the actual game Wordle.

So if we break down the entire game, we basically need to create 2 functions:

  1. To check if the letters are at correct index.
  2. To check if the letters at wrong index exist in the actual word or not.

Let’s start with assigning todays word and number of tries that we want to allow

Then we can create a function that will take 2 words(one actual and other guessed word) and return us a list of indexes where letters are matching

Then we can create another function which will again take 2 words and return us a list of indexes of the letters in the guessed word which are also a part of actual word(be it correct index or not). It will also return us a list of indexes for letters which are not part of the actual word.

Then we can start a loop with range as number of tries we want to give and take input from the user. On the input we will apply a check on the word size to only take word of length 5. Then we will run our index_check function to get the list of index where the words are placed correctly. If the size of this list is equal to the size of our actual word, it means that guess is correct.

If all the words are not at correct position we can then run our letter_existence function that will give us the lists of index for letters that exist and lists of index for letters that don’t exist in the actual word.

Now as we don’t have a UI, we’ll need to print all the collected details in a way that the player can understand and use them to guess the word in next try. Using the index of non existing words we can collect the letters in a list that we will print later. Also we’ll print the list of letters and respective indexes with correct position, and the lettres and index with wrong position.

AND IT’S READY

Do checkout the full code at https://github.com/maxsanwal/Easy-Wordle and let me know if we can make it better in some way.

--

--

Seemant Singh
Seemant Singh

Written by Seemant Singh

Writer, developer, developing writer.

No responses yet