[Tutor] Recursive permutation

x x unigeek at hotmail.com
Fri Nov 19 19:12:06 CET 2004


Here is my 2 cents worth.
If I understand what you are trying to get you just need to take each string 
in Result and create all possible orders of it into a new list.

Result = ['']

def Combination(S):

    if len(S)>0:
        if S not in Result:
            Result.append(S)
            for I in range(len(S)):
                str2= S[0:I] + S[I+1:len(S)]
                Combination(str2)

    return Result


Combination("123456")
Result.sort()

print Result





>>This code maks a permutation of the entire list (all the 3 digs), but how 
>>do I make the permutations of lower lists?
>>Going one down i seems easy: Remove alle the element one at a time and 
>>make a permultation of the rest. But going two down...

>>Like this:
>>Sting = 123
>>This give: 
>>['1','2','3','12','13','21','23','31','32','123','132','213','231,'312',321']
>
>I think you're missing the list of length 0 ('') in your output...
>
>Later,
>Blake.
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor

_________________________________________________________________
Take charge with a pop-up guard built on patented Microsoft® SmartScreen 
Technology. 
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines 
  Start enjoying all the benefits of MSN® Premium right now and get the 
first two months FREE*.



More information about the Tutor mailing list