python
Published on January 26, 2024By DeveloperBreeze
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)
Comments
Please log in to leave a comment.