I do not know if an exact term exists for this type of sorting. Here is the problem - I have a class foo
class foo: def __init__(self,a1,a2): self.attrb1 = a1 self.attrb2 = a2 def sort(self): return self.attrb1
The bar array contains objects of type foo. I want to sort an array in descending order according to two attributes. attrb1 first
bar.sort(key=foo.sort,reverse=True)
Then I want to sort the sorted items inside myself according to attrb2 . So, for the two elements foo1 and foo2 in the array, we have -
foo1 > foo2 if foo1.attrb1 > foo2.attrb1 elif foo1.attrb1 == foo2.attrb1 foo1.attrb2 > foo2.attrb2
How can i do this?
Bruce source share