python anagram finder
August 13, 2008 Leave a comment
This is a silly little program that finds anagrams. Just hangin out practicing python-fu, and this was a challenge I found online.
#!/usr/bin/env python """ This is a word descrambler for each word in wordlist. This may be terribly inefficient, but I only have 10 words to unscramble, so it's fine plus it only takes about .1 second per word on my am2 3000 """ import sys file = open("./wordlist") dictionary = [] dictfile = open("/usr/share/dict/words") for i in dictfile: i = i.strip() dictionary.append(i) for scramword in file: scramword = scramword.strip() numletters = len(scramword) for word in dictionary: #first check that lengths are = if len(word) == numletters: isword = True for letter in word: if letter not in scramword: isword = False break #by this time most words are gone but there #may still be some superfluous guys for letter in scramword: if letter not in word: isword = False break if isword: print word