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.

Continue Reading:

Sort a List

Published on January 26, 2024

python

Sorting a Dictionary by Values

Published on January 26, 2024

python

Sorting an Array

Published on January 26, 2024

javascript

Sorting an Array in JavaScript

Published on January 26, 2024

javascript