class Person:
def __init__(self, name, age):
self.name = name
self.age = age
# Create instances of Person
people = [Person('Alice', 30), Person('Bob', 25), Person('Charlie', 35)]
# Sort people by age using a lambda function as the key
sorted_people = sorted(people, key=lambda x: x.age)
Sort List of Objects by Attribute in Python
python
Continue Reading
Discover more amazing content handpicked just for you
Code
javascript
Sorting an Array in JavaScript
No preview available for this content.
Jan 26, 2024
Code
python
Sorting a Dictionary by Values
No preview available for this content.
Jan 26, 2024
Discussion 0
Please sign in to join the discussion.
No comments yet. Start the discussion!