def keymap_replace_substrings(target_str,
                              mappings={"<": "left_angle_bracket",
                                        ">": "right_angle_bracket",
                                        "[": "left_square_bracket",
                                        "]": "right_square_bracket",
                                        "{": "left_curly_bracket",
                                        "}": "right_curly_bracket",
                                        "\n": "newline"}):
    """Replace parts of a string based on a dictionary.
    This function takes a dictionary of
    replacement mappings. For example, if I supplied
    the string "Hello world.", and the mappings
    {"H": "J", ".": "!"}, it would return "Jello world!".
    Warning: replacements are made iteratively,
    meaning multiple replacements could occur.
    :param target_str: (str)
        The string to replace characters in.
    :param mappings: (str)
        A dictionary of replacement mappings.
    :return: (str)
        String with values replaced
    """
    for substring, replacement in mappings.items():
        target_str = target_str.replace(substring, replacement)
    return target_str