if a[0] in sort_order and b[0] in sort_order:
    if sort_order.index(a[0]) > sort_order.index(b[0]):
        return 1
else:
    return -1
if sorted([a[0].lower(), b[0].lower()]).index(a[0].lower()) == 0:
    return -1
elif sorted([a[0].lower(), b[0].lower()]).index(a[0].lower()) == 1:
    return 1
else:
    raise ValueError('Unhandled condition for values %s, %s' % (a, b))
if isinstance(obj, collections.Mapping):
    pass
python - complex sorting of nested data