Figure out the input format and convert the data to the opposing output format

def flip(template, in_format=None, out_format=None, clean_up=False, no_flip=False, long_form=False):
    """
    Figure out the input format and convert the data to the opposing output format
    """

    # Do we need to figure out the input format?
    if not in_format:
        # Load the template as JSON?
        if (out_format == "json" and no_flip) or (out_format == "yaml" and not no_flip):
            in_format = "json"
        elif (out_format == "yaml" and no_flip) or (out_format == "json" and not no_flip):
            in_format = "yaml"

    # Load the data
    if in_format == "json":
        data = load_json(template)
    elif in_format == "yaml":
        data = load_yaml(template)
    else:
        data, in_format = load(template)

    # Clean up?
    if clean_up:
        data = clean(data)

    # Figure out the output format
    if not out_format:
        if (in_format == "json" and no_flip) or (in_format == "yaml" and not no_flip):
            out_format = "json"
        else:
            out_format = "yaml"

    # Finished!
    if out_format == "json":
        if sys.version[0] == "3":
            return dump_json(data)
        else:
            return dump_json(data).encode('utf-8')

    return dump_yaml(data, clean_up, long_form)