One way is to define in your class the __lt__() and __eq__() methods that tell Python how one instance of your class should be sorted compared to another:
class A(): def __init__(self): self.sortattr = 'anniversary_score'
Then just use sort() , as for a list of numbers, strings, etc.:
mylist.sort()
source share