anagram finder / dict mapping question
dave
squareswallower at 1ya2hoo3.net
Wed May 7 21:02:12 EDT 2008
Hi All,
I wrote a program that takes a string sequence and finds all the words
inside a text file (one word per line) and prints them:
def anagfind(letters): #find anagrams of these letters
fin = open('text.txt') #one word per line file
wordbox = [] #this is where the words will go
for line in fin:
word = line.strip()
count = 0
for char in letters:
if char not in word:
break
else:
count += 1
if count == len(word):
wordbox.append(word)
return wordbox
Now I'd like to modify the code to naturally find all anagrams inside a
wordlist. What would be the best way to do this? Using Hints? Is it
possible to iterate over dict keys? How can I make a dict that maps
from a set of letters to a list of words that are spelled from those
letters? Wouldn't I need to make the set of letters a key in a dict?
As always - Thanks for helping someone trying to learn...
Dave
More information about the Python-list
mailing list