Instructables
Picture of Python and Word Lists
One of the challenges of working with large amounts of data in a program is how to do it efficiently. In Python importing the code could not be easier, but everything gets bogged down when you try to work with it and search for items inside of modify it. In these next few examples I will provide several solutions to working with a word list containing practically every word in the English Language to solve various problems.

If you are new to Python - a great first language - everything can be downloaded from here 

Attached is the actual word lists in a .txt file. There are 113,808 individual words, each on their own line.

When you run the program the script and word list need to be in the same folder, otherwise you will get an error to the effect of "no such file exists"
words.txt992 KB
 
Remove these adsRemove these ads by Signing Up

Step 1: Helpful Code Sections

Picture of Helpful Code Sections
Before we begin there are a couple of lines of code that you might find helpful for interpreting what is going on if Python is still new to you.

fin = open('words.txt')  - This line opens up the file (it can be any file)
for line in fin: - This line goes through the file one line at a time up until the 113,809th line
word = line.strip() - This line removes all the white space and formatting so that only the characters in the specific line are stored in a string with variable name word.
bertwert10 months ago
Bigger word list (178 691 words):
http://www.freescrabbledictionary.com/twl06.txt
UOS1 year ago
These will save my life :) I did some before but definitely needed some for analyzing data! Thanks!
Hammock Boy (author)  UOS1 year ago
Glad to help. It is really amazing the way that Python can sort through text. Please let me know if you have any questions or need help.
nice, I think I've done some of these before too!