python anagram finder

August 13th, 2008 by webstersprodigy

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

Tags:

Leave a Reply


No computers were harmed in the 0.190 seconds it took to produce this page.