ss = [(0, 'bb', 'jj'), (1, 'aa', 'mm'), (2, 'aa', 'kk'), (3, 'bb', 'ee'), (
    4, 'gg', 'ff')]
l = []

def insert_sort(l, e, compare):
    lo = 0
hi = len(l)
while lo < hi:
    mid = (lo + hi) / 2
if compare(e, l[mid]):
    lo = mid + 1
else:
    hi = mid
l.insert(lo, e)
ascend_list = []
descend_list = []
for i in ss:
    insert_sort(ascend_list, i, lambda x, y: x[1:] >= y[1:])
for i in ss:
    insert_sort(descend_list, i, lambda x, y: x[1:] < y[1:])
print(ascend_list)
print(descend_list)
Maintain a list sorted by multiple attributes?