title: Compare a permutation to list of words - Python
body: <p>I'm trying to compare the output of a permutation of a string to a txt with pretty much every word in the dictionary. The function itself is an anagram solver.</p>
  
  <p>The function takes word as a parameter. Here's basically what I have</p>
  
  <pre><code>def anagram(word):
  {c for c in permutations(word,len(word))}
  </code></pre>
  
  <p>this output will give me a set of possible combinations of word.</p>
  
  <p>If word = dog, the output will be:</p>
  
  <pre><code>[{'d','g','g'},{'g','o','d'} 
  </code></pre>
  
  <p>plus the other 6 or so combinations.</p>
  
  <p>I want to compare the result of this permutation to a list of words and then return the word(s) which are anagrams of the original word.</p>
  
  <p>So</p>
  
  <pre><code>if result (god or dog or dgo or gdo...) is in word_list:
  return result
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT</p>
  
  <p>Sorry I didn't explicitly say that the word list had already been imported in as a set/list.</p>
  
  <p>The code for that is:</p>
  
  <pre><code>def load_words():
  name = 'words.2-10.txt'
  if isfile(name):
      all_words = [ l.rstrip() for l in open(name, 'r') ]
      as_lists = {}
      for size in range(2, 11):
           as_lists[size] = [ word for word in all_words if len(word) == size ]
      as_sets = { size : (set(words) if words else None) for size, words in as_lists.iteritems() }
      return as_lists, as_sets
  return None, None
  </code></pre>
  
  <p>word_lists, word_sets = load_words()</p>
  
  <p>Apologies!</p>