Python is becoming a popular programming language because it's both powerful and easy to learn, and it's great for exploring word lists. Here are some sample scripts to get you started.
Scripting is powerful and can often do searches RegEx can't, but remember, scripts can only find results from your word list. Searches with our Finder also include external dictionaries.
Click any sample script below to copy it to your clipboard.
Here's a simple script you can use as a template for exploring your own word list, whether you got it from us or you built it yourself.
Once you have a Python environment set up on your computer, you can copy and paste this script, change the "open" statement to point to your text file, and run it to find all the words that start and end with "x" or with the string "de" or whatever.
That's a very specific example, but to find the words you're looking for, all you have to do is replace the test at the end (if word.startswith...) with logic that fits your goal.
import sys # Get the search string from command line, or prompt if it's missing. pattern = sys.argv[1] if len(sys.argv) > 1 else input("Enter Start/End search string: ") # Bail if we didn't get a search string. pattern = pattern.strip().lower() if len(pattern) == 0: sys.exit() # Open the text file in read-only mode. # If it isn't in current directory, specify full path using forward slash ("/") not backslash. with open("XwiJeffChenList.txt") as f: lines = f.readlines() for line in lines: line = line.lower().strip() # strip() removes spaces and newline characters from start and end parts = line.split(';') word = parts[0] # Get the first part of the line, the word before ";" # score = int(parts[1]) # Score isn't used here but this is how you get it if word.startswith(pattern) and word.endswith(pattern): print(word)
A 2021 crossword played on the idea of words with or without the suffix ION. This modification to the program finds words with and without any suffix you enter.
import sys suffix = sys.argv[1] if len(sys.argv) > 1 else input("Enter suffix: ") suffix = suffix.strip().lower() suffixLength = len(suffix) if suffixLength == 0: sys.exit() with open("XwiJeffChenList.txt") as f: lines = f.readlines() count = 0 fullWordList = [] for line in lines: line = line.lower().strip() parts = line.split(';') fullWord = parts[0] fullWordList.append(fullWord) # All words get added to list # if the word ends with our suffix, see if the word without the suffix is already in the list. # Note, this assumes words in alphabetical order, eg, PASS would precede PASSION in the list. if fullWord.endswith(suffix): truncatedWord = fullWord[: -suffixLength] if truncatedWord in fullWordList: print(truncatedWord + ":" + fullWord) count += 1 print(f'{count} found')
A 2022 crossword combined 4-letter words to build up 16-letter theme answers. This program searches a word list for all such possible answers. Variable types are declared. That's not necessary for these short programs, but it's good practice.
from typing import List count: int = 0 # number of matches found List4: List[str] = [] # collection of all the 4-letter words List16: List[str] = [] # collection of all the 16-letter words with open("XwiJeffChenList.txt") as f: lines: List[str] = f.readlines() # Read the file and collect all the 4- and 16-letter words for line in lines: line = line.lower().strip() parts: List[str] = line.split(';') word: str = parts[0] # Get the first part of the line, the word before ";" if len(word) == 4: List4.append(word) elif len(word) == 16: List16.append(word) # Loop through all the 16-letter words. Break each down into quarters, # and print it out if each part is a known 4-letter word. for word16 in List16: part1: str = word16[0:4] part2: str = word16[4:8] part3: str = word16[8:12] part4: str = word16[12:16] if part1 in List4 and part2 in List4 and part3 in List4 and part4 in List4: print(f'{part1}-{part2}-{part3}-{part4} = {word16}') count += 1 print(f'{count} found')
This script builds on the first sample by replacing the simple start/end test with a RegEx match.
You can explore RegEx on our Finder page and see some RegEx examples here.
import re, sys from typing import Pattern, List pattern: str = sys.argv[1] if len(sys.argv) > 1 else input("Enter RegEx: ") pattern = pattern.strip() count: int = 0 if len(pattern) == 0: sys.exit() # Compile the pattern into a RegEx Object, so it only has to be evaluated once. prog: Pattern[str] = re.compile(pattern.replace("$v", "[aeiou]").replace("$c", "[^aeiou]"), re.IGNORECASE) with open("XwiJeffChenList.txt") as f: lines: List[str] = f.readlines() for line in lines: line = line.lower().strip() parts = line.split(';') word: str = parts[0] if prog.search(word): print(word) count += 1 print(f'{count} found')
Specify, say, "aiouy" to show words where the only vowel (if any) is E.
Compare with these Finder results: *-AIOUY using OneLook, and ^[^AIOUY]+$ using Regex.
How would you change the script to select words that only contain letters you specify?
import sys eliminators = sys.argv[1] if len(sys.argv) > 1 else input("Enter letters to eliminate: ") eliminators = eliminators.strip().lower() if len(eliminators) == 0: sys.exit() eliminationArray = list(eliminators) # convert eliminators to array of characters to check with open("XwiWordList.txt") as f: lines = f.readlines() for line in lines: line = line.lower().strip() parts = line.split(';') word = parts[0] score = parts[1] if not any(x in line for x in eliminationArray): print(line)
This example is different. There's no user input. It sorts a copy of your word list so the highest value words are on top. Within each score, words are sorted by length, and then alphabetically within each score/length group.
I'm not saying this particular sort is useful, but it demonstrates how to do it.
If you do re-sort your word list with a Python script, you probably want to run your program from the command line and then "pipe" it to a new text file. Open a Command Prompt, navigate to your folder, and type something like: main.py > MyNewTextFile.txt
# Define the class AnswerWord that, for each word in our word list, # encapsulates the word, the length of the word, and the score. class AnswerWord(object): def __init__(self, word="", score=0): self.word = word self.length = len(word) self.score = score AnswerWordArray = [] # This array will hold a collection of AnswerWord objects # Use our usual logic to loop through the file. For each line, create a new AnswerWord object # and add it to the array for later sorting. with open("XwiWordList.txt") as f: lines = f.readlines() for line in lines: line = line.lower().strip() parts = line.split(';') AnswerWordArray.append(AnswerWord(parts[0], int(parts[1]))) # Python sorting leaves order intact for entries not affected by the current sort criterion. # First sort words alphabetically. # Then sort by length, which leaves the entries grouped by length but still alphabetized # within each group. # Then sort by reverse score, so all the high value words are first, from shortest to longest. AnswerWordArray.sort(key=lambda k: k.word) AnswerWordArray.sort(key=lambda k: k.length) AnswerWordArray.sort(key=lambda k: k.score, reverse=True) for answerWord in AnswerWordArray: print(answerWord.word + ";" + str(answerWord.score))
The rest is up to you, your ingenuity, and your creativity. Have fun!
If you're serious about learning Python, XWord Info recommends PyCharm. The free "Community" version works fine.