title: Python - Recursive word list
body: <p>I'm trying to get make an <strong>anagram algorithm</strong>, but I'm stuck once I get to the recursive part. Let me know if anymore information is needed.</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>def ana_words(words, letter_count):
      """Return all the anagrams using the given letters and allowed words.
  
      - letter_count has 26 keys (one per lowercase letter),
        and each value is a non-negative integer.
  
      @type words: list[str]
      @type letter_count: dict[str, int]
      @rtype: list[str]
      """
      anagrams_list = []
      if not letter_count:
          return [""]
  
      for word in words:
          if not _within_letter_count(word, letter_count):
              continue
  
          new_letter_count = dict(letter_count)
  
          for char in word:
              new_letter_count[char] -= 1
  
          # recursive function
          var1 = ana_words(words[1:], new_letter_count)
  
          sorted_word = ''.join(word)
  
          for i in var1:
              sorted_word = ''.join([word, i])
  
          anagrams_list.append(sorted_word)
  
      return anagrams_list
  </code></pre>
  
  <p>Words is a list of words from a file, and letter count is a dictionary of characters (<em>already in lower case</em>). the list of words in words is also in lowercase already. </p>
  
  <p><strong>Input:</strong> print ana_words('dormitory')</p>
  
  <p><strong>Output I'm getting:</strong></p>
  
  <pre><code>['dirtyroom', 'dotoi', 'doori', 'dormitory', 'drytoori', 'itorod', 'ortoidry', 'rodtoi', 'roomidry', 'rootidry', 'torodi']
  </code></pre>
  
  <p><strong>Output I want</strong>:</p>
  
  <pre><code>['dirty room', 'dormitory', 'room dirty']
  </code></pre>
  
  <p>Link to word list: <a href="https://1drv.ms/t/s!AlfWKzBlwHQKbPj9P_pyKdmPwpg" rel="nofollow noreferrer">https://1drv.ms/t/s!AlfWKzBlwHQKbPj9P_pyKdmPwpg</a></p>