I think I found why. That is because there are some nan in dpd.txt.
And nan is unable to compare:
float('nan') > 1 # False while float('nan') < 1 # False
So this totally breaks comparison.
If you change your key compare function to:
def _key(id_):
import math
result = -dpd[index_map[id_]], id_.lower()
if math.isnan(result[0]):
result = 0, id_.lower()
return result
It will work.
1
solved Python: Is there any reason a subset of a list would sort differently than the original list?