title: Python - Total number of permutation of a string
body: <p>I had to program a method that printed all permutations of a string and how many there were.</p>
  <pre><code>def generate_anagrams(s):
    global np # variable to count the number of anagrams generated.
    a = list(s)
    np=0
    permutations(a,0)
    print(&quot;There are&quot;, np, &quot;anagrams&quot;)
  
  def permutations(a,i=0): # generate all permutations of a[i:]
    global np
    
    if i == len(a):
      print(''.join(a))
    for j in range(i, len(a)):
      copyString = [k for k in a]
      copyString[i], copyString[j] = copyString[j], copyString[i]
      permutations(copyString,i+1)
      np += 1 
  </code></pre>
  <p>So when I do: <code>genera_anagramas(&quot;ab&quot;)</code> the output should be:</p>
  <pre><code>ab
  ba 
  There are 2 anagrams.
  </code></pre>
  <p>However, the count is returning :</p>
  <pre><code>ab
  ba
  There are 4 anagrams
  </code></pre>
  <p>How do I fix this?</p>