A permutation on permutations

Arthur Siegel ajs at ix.netcom.com
Sun Nov 25 21:09:38 CET 2001


Phil writes -

>Can you have the same number appearing twice, e.g. [1,2,3,3] ?

Actually I hadn't considered double points for what I'm doing. 
But I believe that the universe of unique curves would 
include curves with double point args. I'll play with it and see
if I can get a better criteria for unique curves. 

>>So am a looking for a function to return all
>>permutations, excluding duplicates as defined above.

>Consider the following source:

>def perm(source, done=0, current=[]):
>   if done == len(source): 
>      if current[0] < current[-1]: #removes reversals
>         print current
>   else:
>      for i in source:
>         if i not in current:
>            perm(source, done+1, current+[i])

Works nice, but I haven't found a great way to get a return
value.  Using a global L=[] in the calling code and 
an L.append(current) at "print current" in the perm func.

Thanks.

Art






More information about the Python-list mailing list