1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Finding all possible permutations of a given string in python [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a string. I want to generate all permutations from that string, by changing the order of characters in it. For example, say:

    x='stack'


    what I want is a list like this,

    l=['stack','satck','sackt'.......]


    Currently I am iterating on the list cast of the string, picking 2 letters randomly and transposing them to form a new string, and adding it to set cast of l. Based on the length of the string, I am calculating the number of permutations possible and continuing iterations till set size reaches the limit. There must be a better way to do this.

    Continue reading...

Compartilhe esta Página