Another generator solution, based on computing a permutation from its rank 
according to some natural order. Written for strings.

def perms(s) :
     def nth(n,L,k=1) :
         if k>len(L) :
             if n :
                 raise StopIteration
             return ''
         return nth(n/k,L,k+1)+L.pop(n%k)
     for n in xrange(1<<30) :
         yield nth(n,list(s))
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to