Funny, I even did not know that you can't do that.
But there is a solution. You can use the key-function to convert
the keys to a tuple or list. Then this object is used for comparison.
It depends on what you want to reach.
But there is a solution. You can use the key-function to convert
the keys to a tuple or list. Then this object is used for comparison.
sorted([{-21: None, 2: None}, {-100: None, -2: None}], key=lambda x: tuple(x.keys()))The key-function can also written as normal function:
def dict_sort(mapping): return tuple(mapping.keys())
sorted([{-21: None, 2: None}, {-100: None, -2: None}], key=dict_sort)You can also choose a key, which you want to use for sorting or you can select values to sort the dict.
It depends on what you want to reach.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!