i have a list of strings like this:
['id:9', 'vector:1', 'table:1', 'product:10', 'number:3', 'Number:4']
i want to sort it from higher integer value to lower and then the rest:
['product:10', 'id:9', 'Number:4', 'number:3', 'vector:1', 'table:1']
the values are all integer without including 0, the string that are attached to them can be all lower case, all upper case, part lower case, part upper case, while also being similar to another item: Number, NUMBER, number, NUMber
i tried using natsort but that didn't arrange them correctly, also i tried some other solutions discussed here still didn't work in my case, so how can this be done in python?
If you create a function converting each string to a tuple you can then sort on those tuples:
If you want to understand what's going on under the covers, this shows you what is actually being sorted (in ascending order):
sortlooks first to the first element of each tuple - the integer - and only in the case of a tie it then looks to the second element - the string.