def lookup(instruction, instructions = None):
    """Looks up instruction, which can either be a function or a string.
    If it's a string, returns the corresponding method.
    If it's a function, returns the corresponding name.
    """
    if instructions is None:
        instructions = default_instructions

    if isinstance(instruction, str):
        return instructions[instruction]
    elif hasattr(instruction, "__call__"):
        rev = dict(((v,k) for (k,v) in instructions.items()))
        return rev[instruction]
    else:
        raise errors.MachineError(KeyError("Unknown instruction: %s" %
            str(instruction)))
Looks up instruction, which can either be a function or a string.
    If it's a string, returns the corresponding method.
    If it's a function, returns the corresponding name.