I have a hashtable and a lambda for sort like this:
h = {"hlllleleo": 9, "hello": 5, "fgfgggf" : 7, "abcdefgh": 8}
lbda = lambda x : h[x]
from collections import OrderedDict as od
od({x:h[x] for x in sorted(h, key=lbda)})
#Outputs:
OrderedDict([('abcdefgh', 8), ('hlllleleo', 9), ('fgfgggf', 7),
('hello', 5)])
Why is the ordered dict not coming out sorted as it is built? If I loop over sorted() it is sorted:
for x in sorted(h, key=lbda):
print x, h[x]
# Outputs:
hello 5
fgfgggf 7
abcdefgh 8
hlllleleo 9