Programming Languages Python Subjective
Sep 30, 2025

How do you sort a list of dictionaries by a specific key?

Detailed Explanation
students = [{"name": "John", "age": 25}, {"name": "Jane", "age": 22}]\n\n# Sort by age:\nsorted_students = sorted(students, key=lambda x: x["age"])\n\n# Or using operator.itemgetter:\nfrom operator import itemgetter\nsorted_students = sorted(students, key=itemgetter("age"))
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback