79701840

Date: 2025-07-15 09:39:37
Score: 0.5
Natty:
Report link

The very good answer from @Andrew Clark gives the right direction, but unfortunately it answers the original question only partly ;-)

There are 2 aspects to be fulfilled:

Here is the universal solution, which will do the job:

sorted(l, key=lambda x: (x is None, str(type(x)), x))

If it's not needed to place the None values to the end of result list, the code is:

sorted(l, key=lambda x: (str(type(x)), x))

Main idea: group elements by their type and sort only elements within same type.
In case a further special handling required by sorting (e.g. try to check whether string value contains only integer and then sort it as if it would be an integer) - an extra own key-function might be needed.
Hope - it helps ;-)

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @gives
  • User mentioned (0): @doesn't
  • Low reputation (0.5):
Posted by: Dr.CKYHC