class a:
c = 1
def __init__(self, c):
self.c=c
def __str__(self):
return str(self.c)
__repr__ = __str__
def __lt__(self, other):
if self.c<other.c:
return -1
else:
return 1
return -1
if __name__ == '__main__':
b = [a(1),a(3),a(2)]
print(b)
b = sorted(b)
print(b) [1, 3, 2]
[2, 3, 1]



京公网安备 11010502036488号