Skip to content
Advertisement

Sort dict by multiple keys and with int and None data in python

so I have a dict :

JavaScript

I want to sort my dict on ‘i.chromosome’, ‘i.linkageGroup’ and ‘i.positionCm’

What I am doing :

JavaScript

And i got :

JavaScript

In python 2, they were doing :

JavaScript

Could you help me please, I am lost !

Advertisement

Answer

Given

JavaScript

and the requirement that Nones are for int, you can solve it using

JavaScript

where I’ve made the assumption that the numbers you have are 0 or positive. If you can also have negatives you need to change the -1 to a very large negative number.

The result:

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