I have a list of dictionaries and want each dictionary to be sorted by value
list=[{ 1:0.2, 3:0.1, 5:0.8},{ 6:0.8, 9:0.6, 10:0.7}]
when sorted by value it should become:
[{ 3:0.1, 1:0.2, 5:0.8},{ 9:0.6, 10:0.7, 6:0.8}]
I have a list of dictionaries and want each dictionary to be sorted by value
list=[{ 1:0.2, 3:0.1, 5:0.8},{ 6:0.8, 9:0.6, 10:0.7}]
when sorted by value it should become:
[{ 3:0.1, 1:0.2, 5:0.8},{ 9:0.6, 10:0.7, 6:0.8}]
Starting from python 3.7 dictionaries are insertion ordered, so you could do it in the following way:
lst = [dict(sorted(d.items(), key=lambda x: x[1])) for d in lst]