About 526,000 results
Open links in new tab
  1. python - How to sort a list of strings? - Stack Overflow

    Aug 30, 2008 · 8 But how does this handle language specific sorting rules? Does it take locale into account? No, list.sort() is a generic sorting function. If you want to sort according to the Unicode …

  2. How to sort the letters in a string alphabetically in Python

    1 the code can be used to sort string in alphabetical order without using any inbuilt function of python k = input ("Enter any string again ")

  3. python - Is there a built in function for string natural sort? - Stack ...

    The built-in Python function re.Pattern.split(string) (or its close relative re.split(pattern, string)) does exactly that, provided that the regex pattern (a range of one or more digits), which here acts as a …

  4. python - Sort list of strings by a part of the string - Stack Overflow

    Jan 29, 2014 · Sort list of strings by a part of the string Asked 11 years, 10 months ago Modified 3 years, 11 months ago Viewed 39k times

  5. Sorting Python list based on the length of the string

    Decorate-Sort-Undecorate Design Pattern : Python’s support for a key function when sorting is implemented using what is known as the decorate-sort-undecorate design pattern. It proceeds in 3 …

  6. python - How to correctly sort a string with a number inside? - Stack ...

    How to correctly sort a string with a number inside? [duplicate] Asked 14 years, 7 months ago Modified 5 years, 4 months ago Viewed 178k times

  7. python - How to sort a list of strings numerically - Stack Overflow

    list1 = [int(x) for x in list1] list1.sort() If for some reason you need to keep strings instead of ints (usually a bad idea, but maybe you need to preserve leading zeros or something), you can use a key function. …

  8. python - Custom sorting a single string - Stack Overflow

    Mar 29, 2025 · I have a list of five-character strings, each string representing a hand of five playing cards. I want to sort each string so it's in ascending order by number, followed by the cards …

  9. python - How to sort a list by length of string followed by reverse ...

    the_list.sort(key=len, reverse=True) # sorts by descending length Python's sort is stable, which means that sorting the list by length leaves the elements in alphabetical order when the length is equal.

  10. python - Sort list of strings by length and alphabetically - Stack Overflow

    Jan 26, 2021 · You want to sort the list of elements by minus their length and then alphabetically, so you want the key of a string s to be the tuple (-len(s), s). Hence: