sorting - Sort dictionary of dictionaries by value Python ( 3 Level Dict ) -
i have dict this:
{ 'int-abc1': { 'acc1': {'val': -22313.7381693064, 'qua': -241.0}, 'acc2': {'val': -1312.940854148, 'qua': -13.0} }, 'int-abc2': { 'acc1': {'val': -131.2510359399, 'qua' : -23.0}, 'acc3': {'val': -131.40521409002, 'qua' : -13.0}, 'acc5': {'val': -12312.7688190937, 'qua' : -1313.0} } } i need sort 'val' , similar dict out of it.
something work, think if starting python, should learn sorted function in python.
>>> sorted(k.items(), key = lambda x: x[1][0].itervalues().next()['val']) where k dictionary.
link provided viki.omega9 in answer should starting point.
note: command return list of tuples (or pairs) in sorted order of form:
[(key1, val1), (key2, val2)] because dictionaries nature unordered.
Comments
Post a Comment