Mar-17-2017, 09:29 AM
Simple sorting where numbers are sorted naturally and come before everything else could be achieved in python3 with:
In [5]: a = [3, 2.34, 1, 'string', '5th May', 11] In [6]: sorted(a, key=lambda x: (0, x) if isinstance(x, (int, float)) else (1, str(x))) Out[6]: [1, 2.34, 3, 11, '5th May', 'string']As higher position elements are used only to resolve ties, it wont crash due to incomparable types.