from random import randint
from collections import deque
class Box:
def __init__(self, l, w, h):
self.l, self.w, self.h = l, w, h
def key(self): return - self.l - self.w
def __repr__(self): return f"Box {self.l} x {self.w} x {self.h}"
N = 10
stack = deque(Box(*map(randint, (10,) * 3, (50,) * 3)) for _ in range(N))
lst = sorted(reversed(stack), key = Box.key)
print(*lst, sep = '\n')
Пояснения тут: https://otvet.mail.ru/question/233818132