Convert Text Into a Word List
00:13 This allows you to create special themed word list containing programming-related terms, city names, or non-English words, amongst many other options. You’ll create a script that converts any text file into a nicely formatted word list that you can use in your Wordle clone.
01:41 Note that key has two arguments passed to it. The first is a lambda expression sorting the words by length in ascending order. The second is the word itself, allowing words of equal length to be sorted in alphabetical order.
01:55 This isn’t strictly necessary, but makes reading the list easier. Finally, the word list is written to the output file at the path specified in the second argument. Once saved, you can use the script to convert your current version of Wordle to a word list as seen on-screen.
Take a look at your new word list. You’ll recognize some of the words from your code. However, note that only some words went into the word list. Also, take note to the fact you don’t filter out words that are more or less than five letters long. You could do that when you are building the word list, but by leaving that job for your wyrdl.py
code, you gain some flexibility.
02:56 This makes it possible to use a general word list and to change the word length in the game. Maybe you want to create a Wordle variant that quizzes the user about seven-letter words. You can now generate your personal word list.
Find any plain text file and run create_wordlist.py
on it. You could, for example, download the complete works of Shakespeare to create an old style word list or a version of Alice in Wonderland retold in words of one syllable to create a list of simpler words.
04:05 Remember that you can check your code against the code in the course materials if you have any problems running the game. There are versions of the files included for each numbered section of the course, so you should be able to get back on track if you need to.
04:17 But also remember that it’s worth spending some time looking at code that doesn’t work and seeing if you can figure out what’s happening that isn’t intended. This is a key skill that you’ll use a lot.
04:29 Your game is more interesting now that the secret word is chosen at random from a word list, and later on in the course, you’ll work on making the user experience nicer with more intuitive feedback.
Become a Member to join the conversation.