A friend of mine was talking about a word game she liked to play where you try to convert one word to another (they have the same number of letters) by switching one letter at a time, where each iteration produces a real word.
Example:
MOON --> WOLF
GOON
GOOF
GOLF
WOLF
I figured it'd be a fun little project to write a program to generate solutions, and taking it further, given 2 words, determine if a solution exists and the number of iterations in optimal solution.
Problem is I'm having trouble finding free word lists that I can easily access programmatically. I'm also thinking about using this as an excuse to learn Python, so it'd be great if anyone knows of free word lists and pointers on how to parse and access it from Python. The algorithm for figuring out how to find an optimal path I'll work on my own.
Options:
- Look for /usr/share/dict/words on your common or garden variety Unix install.
- http://www.ibiblio.org/webster/
- http://wordlist.sourceforge.net/
- http://svnweb.freebsd.org/csrg/share/dict/ (click the 'revision' tag of the file 'words')
#4
is the one I used for my own Python experiment into word games, and it worked nicely.
For bonus points, here's something to get you started on your word program:
import re
startwith = "MOON"
endwith = "GOLF"
cklength = re.compile('.{' + str(len(startwith)) + '}(\n)?$', re.I)
filename = "C:/dict.txt"
words = set(x.strip().upper() for x in open(filename) if x.match(cklength))
Words will then be a set of all 4 letter words in the dictionary. You can do your logic from there.
Most unix (which includes osx) have a file /usr/share/dict/words
.
You can find a 2.2mb list of english words here.
You can access them using the file i/o functions.
if you have access to a linux install, there should be some word lists in
/usr/share/dict/
For something similar I have used the mozilla English dictionary. It is a zip file (even though it has another extension). Inside you will find en-GB.dic which is the dictionary.
I was having the same issue and with some digging into a scrabble based site, I found several of their word lists in a nice text format. They have an English version at https://www.wordgamedictionary.com/english-word-list/
来源:https://stackoverflow.com/questions/772922/free-word-list-for-use-programmatically