def mro_merge(*args):
    for i, arg in enumerate(args):
        if len(arg) > 0:
            head = arg[0]
for argb in args:
    if head in argb[1:]:
        break
else:
    newargs = tuple(argb if len(argb) > 0 and argb[0] != head else argb[1:] for
        argb in args)
print('mro_merge(%s) = %s + mro_merge(%s)' % (args, head, newargs))
Python MRO order