Given this simplified example to sort:
l = [10, '0foo', 2.5, 'foo', 'bar']
I want to sort l
so that numeric is always before strings. In this case, I'd like to get [2.5, 10, '0foo', 'foo', 'bar']
. Is it possible make numeric and string temporarily comparable (with strings always larger than numeric)?
Note it is not easy to provide a key
function to sorted
if you are thinking about it. For example, converting numeric to string won't work because "10"
< "2.5"
.