Popular recipes by nnarula http://code.activestate.com/recipes/users/4168533/2008-12-22T06:11:55-08:00ActiveState Code RecipesEfficient generation of permutations (Python) 2008-12-22T06:11:55-08:00nnarulahttp://code.activestate.com/recipes/users/4168533/http://code.activestate.com/recipes/576593-efficient-generation-of-permutations/ <p style="color: grey"> Python recipe 576593 by <a href="/recipes/users/4168533/">nnarula</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/permutations/">permutations</a>). </p> <p>This code builds an iterator on the fly that will successfully return unique permutations of n integers, m at a time (nPm). It does not use recursion, so stack size is not a problem. Sample usage it= build(n,p) <br /> it.next() # returns permutation</p> <p>it=build(n) is the same as build(n,n) do it will generate n! unique permuatations.</p> <p>I worte it over the weekend and have tested it reasonably for n upto 30 and p from 1 to 30 </p>