I have a dictionary as the following data structure:
d = {'TRANSFERRED': [2281, 1031, 1775, 867, 1242],
'CLOSED': [239, 269, 645, 540, 388],
'DEFERRED': [89, 5, 68, 48, 37],
'OPEN': [3, 0, 2, 1, 0],
'IN PROGRESS': [0, 2, 4, 0, 5],
'QUEUED': [0, 0, 0, 0, 0]}
The dictionary contains lists with numeric values and I would like to order them from the lowest to the highest value, something like this:
d = {'TRANSFERRED': [867, 1031, 1242, 1775, 2281],
'CLOSED': [239, 269, 388, 540, 645],
'DEFERRED': [5, 37, 48, 68, 89],
'OPEN': [0, 0, 1, 2, 3],
'IN PROGRESS': [0, 0, 2, 4, 5],
'QUEUED': [0, 0, 0, 0, 0]}
I am concerned that dictionaries cannot be sorted because they are inherently orderless but other types such as lists and tuples are not orderless, moreover, I have been using the following trick to order dictionaries with lists that contain single items such as:
d2 = {'TRANSFERRED': [-2281],
'CLOSED': [239],
'DEFERRED': [489],
'OPEN': [34],
'IN PROGRESS': [0],
'QUEUED': [-10]}
sorted(d2.items(), key=lambda x: x[1], reverse=True)
The result gives the following sorted data structure:
[('DEFERRED', [489]),
('CLOSED', [239]),
('OPEN', [34]),
('IN PROGRESS', [0]),
('QUEUED', [-10]),
('TRANSFERRED', [-2281])]
I want to replicate this same result but with a dictionary with lists of multiple numeric values. How can I achieve this? Please, feel free to use the following link repl.it - sort dictionary with lists of multiple items to test your results. Feedback or comments to improve this question are welcome.