Counting permuations in Python
<p>What is the fastest way of counting the number of permutations? I have the following problem:</p>

<p>First I have this:</p>

<pre><code>ncombos = itertools.combinations_with_replacement(['a1', 'a2', 'a3'], years*n)
('a1', 'a1', 'a1')
('a1', 'a1', 'a2')
('a1', 'a1', 'a3')
('a1', 'a2', 'a2')
.... etc.....    
('a3', 'a3', 'a3')
</code></pre>

<p>The aim is to go through each one and calculate the number of permutations that each one has and construct an array with these values. I implemented this using:</p>

<pre><code>nodes = np.ones(len(leafs)); i=0  #This will store the number of permutations

for j in ncombos:
    nodes[i] =len(list(set(itertools.permutations(np.asanyarray(j), n))))
    i = i+1
</code></pre>

<p>np.asanyarray(j) converts the ('a1','a1','a1') into formal ['a1','a1', 'a1'] which is need for permutations() to work. set erases the permutations which are identical. list makes a list of this. len calculates how many permutations can i make with a1, a1, a1. </p>

<p>So basically all I want is to count the number of permutations... However my code is extremely!!! slow ! Thank you!</p>
