<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def base_ctx(ctx):
 """Get base ctx. :param ctx: initial ctx. :return: base ctx."""


    result = None

    if isclass(ctx):
        result = getattr(ctx, '__base__', None)
        if result is None:
            mro = getmro(ctx)
            if len(mro) > 1:
                result = mro[1]
    else:
        result = ctx.__class__

    return result