I have a list of strings which can represent integers as well as names. The default string compare does the following:
sorted(['1','2','3','4','10','102','14','Alice','John','Sally'])
['1', '10', '102', '14', '2', '3', '4', 'Alice', 'John', 'Sally']
I would like to sort the list as follows:
['1', '2', '3', '4', '10', '14', '102', 'Alice', 'John', 'Sally']
which means:
- sort all strings which represent an integer numerically
- sort the 'real' strings alphabetically and append this list to (1.)
I have tried with a compare method, but I don't know how to determine cleanly if the string represents an integer without try/except?
Thanks in advance