Python: Wordwheel / WordCube solver

Often in newspapers there is a wordwheel or some variant, whereby you have to find as many words greater than 3 letters long, containing the centre word and using the letters no more than once. I have created a webpage that generates a “WordCube” daily for people to peruse at their leisure ( This post contains the code and explanation of the solutions to wordcube’s (and all other word<insert shape here>).

WordCube from for 12/12/2009
Example WordCube image for the 12th December 2009 from

Below is a function I wrote to check if an input was a valid anagram (or partial anagram, as it isn’t essential to use every letter). The function works by cycling over each letter of word we are testing (word), and checks if the letter is valid (checked against chkword). If the letter is valid then it removes the letter from the original word and moves to the next letter until we run out of letters (returns True) or if the letter is invalid (returns False).

def anagramchk(word,chkword):
	for letter in word:
		if letter in chkword:
			chkword=chkword.replace(letter, '', 1)
			return False
	return True

f=open('english', 'r')
word=raw_input('Input letters (starting with mandatory letter) :')
for l in f:
	if len(l)<=len(word) and len(l)>=minlen and word[0] in l and anagramchk(l,word):
		if len(l)==len(word):
			print l,'  <-- Long word'
			print l
print count

This will output a list of the possible words, along with a total. The results can be seen for the WordCube in the example above here (To prevent spoiling it if you’d like to have a go at it yourself).

As always I’d be interested to see if anyone knows any faster methods or any other general improvements or comments.

The dictionary file can be found here (not perfect):


  1. Gav

    Hi Mate,

    Nice little script – do you know if there is an online version of this? I’ve lost the solution to a puzzle we were doing and I can’t find an online solver anywhere…

    If you’re feeling nice…

    Is the one we need a solution for – there certainly doesn’t seem to be an online solver anywhere on teh interwebs, so it might get some traffic for you if you built one – help to promote your app!

  2. mat

    @Gav Hello, I have actually been at work on an online version, it isn’t very pretty at the moment but it will do a half-decent job.

    Your puzzle gives the following answers:

    come, comet, condemn, condiment, demo, demon, demonic, denim, dime, dome, emit, income, item, medic, mend, mention, mice, mien, mince, minced, mind, mine, mined, mint, minted, mite, mode, mote, omen, omit, time, timed, tome,

Leave a Comment

Your email address will not be published. Required fields are marked *