sorting - Sort dict by second value in tuple and return dict -


from collections import defaultdict,ordereddict tt=defaultdict (list)  tt={'abcd':(23,77),'ddef':(55,22)}  c=ordereddict (sorted (tt.items (),key=lambda t: t[1][1]))  print (c) d=list ((k,v) k,v in c.items())  print (d) 

this sorts correctly c.
list makes dict ordereddict

d gets {'ddef':(55,22),'abcd':(23,77)}

modified code. works fine now.
need display top (n) keys in sorted order second element of tuple.
dict seems best route, there ever 50 items in list,i need top ten in order.


Comments

Popular posts from this blog

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

matlab - error with cyclic autocorrelation function -

php - Using grpc in Laravel, "Class 'Grpc\ChannelCredentials' not found." -