<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def format_string(string_to_format, wordstyle="lowercase", separator=" "):
 """ Takes an un-formatted string and returns it in the desired format Acceptable formats are defined in the function_map dictionary. """

    # first split the string up into its constituent words
    words = string_to_format.split(" ")

    # format the individual words
    function_map = {
        "lowercase": format_word_list_lowercase,
        "uppercase": format_word_list_uppercase,
        "capitalize": format_word_list_capitalize,
        "mixedcase": format_word_list_mixedcase
    }

    try:
        words = function_map[wordstyle](words)
    except KeyError:
        msg = "Passed in an invalid wordstyle, allowed styles are {}"
        raise InvalidWordStyleError(msg.format(function_map.keys()))

    # now add in the separator and return
    return str(separator).join(words)