Skip to content
Advertisement

How to sort a dictionary in asc or desc with negative and positive keys?

I’m trying to sort a python dictionary with negative and positives as keys.

Ex:

JavaScript

and the expected output would be

JavaScript

I have tried sorting with the following code. But it is not able to sort properly as the keys are strings and it is not able to sort in the way I wanted.

JavaScript

Any help would be appreciated. Thanks in advance.

Advertisement

Answer

sort as int.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement