import operator sorted(my_list, key=operator.itemgetter("name"))
In addition, itemgetter can take several arguments and returns a tuple of these elements, so you can sort by several keys as follows:
sorted(my_list, key=operator.itemgetter("name", "age", "other_thing"))
The sorted function returns a new sorted list. If you want to sort the list in place, use:
my_list.sort(key=operator.itemgetter("name"))
source share