Sort the list in place twice like so:
lst = [1, -2, 10, -12, -4, -5, 9, 2]lst.sort()lst.sort(key=int(0).__gt__) # key is True for items <= 0
This takes advantage of the fact the python sort
function/method is stable. That means that items with the same value or key stay in the same order. The first sort puts all the items in order from smallest to largest. For the second sort, all the items < 0 get a key of True, all the items >= 0 get a key of False. Because True (1) > False (0), the second sort moves all the negative items to the end, without changing the order of the negative items.