class X(object):
    pass


class B(A, X):
    pass


class C(B):
    pass


class D(C):
    pass
sorted([B, C, A, D, X], key=lambda cls: len(cls.mro()))
How can I sort a list of Python classes by inheritance depth?