Re: How to generate all permutations of a string?

2006-06-26 Thread Boris Borcic
I wrote: > 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 '' >

Re: How to generate all permutations of a string?

2006-06-23 Thread Boris Borcic
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,

Re: How to generate all permutations of a string?

2006-06-22 Thread James Stroud
Girish Sahani wrote: >>>thanks lawrence...however this func doesnt return the permuted strings, >>>so >>>i added some code as follows to generate a list of all the permutations: >>> >>>def permute(seq): >>>l = [] >>>if len(seq) == 0: >>>yield [] >>>else: >>>for i in rang

Re: How to generate all permutations of a string?

2006-06-22 Thread Girish Sahani
>> thanks lawrence...however this func doesnt return the permuted strings, >> so >> i added some code as follows to generate a list of all the permutations: >> >> def permute(seq): >> l = [] >> if len(seq) == 0: >> yield [] >> else: >> for i in range(0,len(seq)): >>

Re: How to generate all permutations of a string?

2006-06-22 Thread James Stroud
Girish Sahani wrote: >>In article <[EMAIL PROTECTED]>, >> "Girish Sahani" <[EMAIL PROTECTED]> wrote: >> >> >>> I want to generate all permutations of a string. >> >>def permute(Seq) : >>"""generator which yields successive permutations of the elements >>of Seq.""" >>if len(Seq) == 0 : >

Re: How to generate all permutations of a string?

2006-06-22 Thread Gerard Flanagan
Girish Sahani wrote: > Hi guys, > I want to generate all permutations of a string. I've managed to > generate all cyclic permutations. Please help :) > http://gflanagan.net/site/python/05/Johnson.html Gerard -- http://mail.python.org/mailman/listinfo/python-list

Re: How to generate all permutations of a string?

2006-06-22 Thread Anton Vredegoor
Girish Sahani wrote: > I want to generate all permutations of a string. I've managed to > generate all cyclic permutations. Please help :) http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496724 anton -- http://mail.python.org/mailman/listinfo/python-list

Re: How to generate all permutations of a string?

2006-06-22 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Girish Sahani <[EMAIL PROTECTED]> wrote: >Hi guys, > I want to generate all permutations of a string. I've managed to >generate all cyclic permutations. Please help :) > >def permute(string): >l= [] >l.append(string) >string1 = '' >for i in range(0,l

Re: How to generate all permutations of a string?

2006-06-22 Thread Maric Michaud
Le Jeudi 22 Juin 2006 10:07, Girish Sahani a écrit : > Hi guys, > I want to generate all permutations of a string. I've managed to > generate all cyclic permutations. Please help :) > Here is mine, maybe more versatile : def permute(iterable) : if len(iterable) == 1 : yield iterable e

Re: How to generate all permutations of a string?

2006-06-22 Thread Girish Sahani
> In article <[EMAIL PROTECTED]>, > "Girish Sahani" <[EMAIL PROTECTED]> wrote: > >> I want to generate all permutations of a string. > > def permute(Seq) : > """generator which yields successive permutations of the elements > of Seq.""" > if len(Seq) == 0 : > yield () > el

Re: How to generate all permutations of a string?

2006-06-22 Thread bayerj
Mind, that Lawrence's solution may contain doubles: >>> [ i for i in permute("aa") ] [('a', 'a'), ('a', 'a')] If you don't want this, use sets. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to generate all permutations of a string?

2006-06-22 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>, "Girish Sahani" <[EMAIL PROTECTED]> wrote: > I want to generate all permutations of a string. def permute(Seq) : """generator which yields successive permutations of the elements of Seq.""" if len(Seq) == 0 : yield () else : for i

How to generate all permutations of a string?

2006-06-22 Thread Girish Sahani
Hi guys, I want to generate all permutations of a string. I've managed to generate all cyclic permutations. Please help :) def permute(string): l= [] l.append(string) string1 = '' for i in range(0,len(string)-1,1): string1 = string[1:len(string)] + string[:1] l.ap