python sort list by value of dictionary code example
Example 1: sort list of dictionaries python
unsorted_list = [{"key1":5, "key2":2}, {"key1":5, "key2":1}]
sorted_list = sorted(unsorted_list, key=lambda k: k["key2"])
Example 2: sorted python lambda
lst = [('candy','30','100'), ('apple','10','200'), ('baby','20','300')]
lst.sort(key=lambda x:x[1])
print(lst)