How do you sort a list of dictionaries by a key?
Model answer
sorted(users, key=lambda u: u["age"]), or use operator.itemgetter("age"). Add reverse=True for descending order. sorted returns a new list. list.sort() changes the list in place.
Learn this topic
Dictionaries, Tuples and Sets in Python in the course Python for Beginners: Learn to Code with Real Projects.
Sign in to add your own answer.