[Tutor] Recursive permutation

x x unigeek at hotmail.com
Fri Nov 19 18:59:38 CET 2004

Here is my 2 bits worth.
If I understand what you want you need only use the Result and make a new 
list that takes each item and creates all possible orders of that item.

Result = ['']

def Combination(S):

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

    return Result


print Result

>From: Blake Winton <bwinton at latte.ca>
>To: Eivind Triel <ET at cheminova.dk>, tutor at python.org
>Subject: Re: [Tutor] Recursive permutation
>Date: Thu, 18 Nov 2004 10:16:12 -0500
>Eivind Triel wrote:
> > Well is there a nice code that will do the trick?
>We've discussed this on the list before, so searching the archive for "list 
>permutation recursive" should yield up some hits.  (Sadly, it doesn't 
>really give me anything.  Maybe someone else on the Tutor list will post 
>the thread title?)
>>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...
>Perhaps it would be easier to start from the bottom, and build your way up? 
>  So, all the lists of length 0, then all the lists of length 1, etc, etc, 
>until you get to all the lists of length len(input).
>>Like this:
>>Sting = 123
>>This give: 
>I think you're missing the list of length 0 ('') in your output...
>Tutor maillist  -  Tutor at python.org

Don't just Search. Find! http://search.sympatico.msn.ca/default.aspx The new 
MSN Search! Check it out!

More information about the Tutor mailing list