[Python] Is there a built in function for string natural sort?

Discussão em 'Python' iniciado por Stack, Julho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list of strings for which I would like to perform a natural alphabetical sort.

    For instance, the following list is naturally sorted (what I want):

    ['elm0', 'elm1', 'Elm2', 'elm9', 'elm10', 'Elm11', 'Elm12', 'elm13']


    And here's the "sorted" version of the above list (what I get using sorted()):

    ['Elm11', 'Elm12', 'Elm2', 'elm0', 'elm1', 'elm10', 'elm13', 'elm9']


    I'm looking for a sort function which behaves like the first one.

    Continue reading...

Compartilhe esta Página