Answers for "python sort array of dictionary by value"

12

how to sort a dictionary by value in python

import operator
x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
sorted_x = sorted(x.items(), key=operator.itemgetter(1))


# Sort by key
import operator
x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
sorted_x = sorted(x.items(), key=operator.itemgetter(0))
Posted by: Guest on November-27-2019
0

python sort array of dictionary by value

my_list = sorted(my_list, key=lambda k: k['name'])
Posted by: Guest on April-19-2021

Code answers related to "python sort array of dictionary by value"

Python Answers by Framework

Browse Popular Code Answers by Language