Answers for "sorting using keys in dict with total value"

1

sort dict by values

dict(sorted(x.items(), key=lambda item: item[1]))
Posted by: Guest on March-17-2021
1

how to sort dict by value

dict1 = {1: 1, 2: 9, 3: 4}
sorted_dict = {}
sorted_keys = sorted(dict1, key=dict1.get)  # [1, 3, 2]

for w in sorted_keys:
    sorted_dict[w] = dict1[w]

print(sorted_dict) # {1: 1, 3: 4, 2: 9}
Posted by: Guest on August-08-2021
0

python sort dict by value

x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
{k: v for k, v in sorted(x.items(), key=lambda item: item[1])}
Posted by: Guest on April-28-2021

Code answers related to "sorting using keys in dict with total value"

Python Answers by Framework

Browse Popular Code Answers by Language