Python: Sort a list of dictionaries
A short, tested Python example for sort a list of dictionaries. Copy it and adjust the names and paths for your project.
Python
people = [{"name": "Ann", "age": 31}, {"name": "Bob", "age": 25}]
by_age = sorted(people, key=lambda p: p["age"])
by_age_desc = sorted(people, key=lambda p: p["age"], reverse=True)Find it in Zest
Search for “python sort a list of dictionaries” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.