How to generate all permutations of a string?

Cameron Laird claird at lairds.us
Thu Jun 22 06:42:07 EDT 2006


In article <mailman.7352.1150963651.27775.python-list at python.org>,
Girish Sahani <girish at cse.iitb.ac.in> 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,len(string)-1,1):
>        string1 = string[1:len(string)] + string[:1]
>        l.append(string1)
>        string = string1
>    return l
>

Those so passionate about enumerations as to consider *everything*
known about them, and not just a specific Python function, will
want to be aware of the referent of <URL:
http://www.unixreview.com/documents/s=10089/ur0606j/ur0606j.html >
and related materials.
and its referents.



More information about the Python-list mailing list