Home > python > Python: crossword solver + dictionary file

Python: crossword solver + dictionary file

September 3rd, 2009 mat Leave a comment Go to comments

This is a quick and dirty crossword solver that I wrote in python:

word=raw_input('Crossword Solver \nuse * as a wildcard: ')
f=open('dic.txt', 'r')
for line in f:
	line=line.strip()
        if len(line)==len(word):
		good=1
		pos=0
		for letter in word:
			if not letter=='*':
				if not letter==line[pos]:
					good=0
			pos+=1
		if good==1:
			print line
f.close()

Example usage:

Crossword Solver
use * as a wildcard: *arn*val
carnival

The dictionary file I used is 608.2Kb with 80,368 english words and avaliable here

Bookmark and Share
Categories: python Tags: ,
  1. Ross
    November 14th, 2009 at 02:30 | #1

    Very cool.
    However, the line “if len(line)==len(word):”
    has one too many indents.

  1. April 28th, 2010 at 17:05 | #1
// unused langs // // // //