Skip to content Skip to sidebar Skip to footer

Sort List Of Ints By The First Digit Of Each Int

I'm trying to figure out how to sort a list of integers by the first digit in each int, (and if the same, move to the next digit, etc.) I'm sure I can just loop through, (although

Solution 1:

Sort with a key of strings and you'll get ASCIIbetical sorting.

>>> myList = [34254, 2343, 49, 595, 323]
>>> sorted(myList, key=str)
[2343, 323, 34254, 49, 595]

Post a Comment for "Sort List Of Ints By The First Digit Of Each Int"