import re


def set_header_depth(text, depth):
    """
    Changes all headers of a markdown formated text based
    on the depth value. does this for "# " until "###### ".
    E.g. 
    depth=2:
    "# Title" -> "### Title"
    depth=1:
    "## Subtitle" -> "### Subtitle" 
    """
    for i in range(1, 6):
        header = r"[\n|^]({} )".format("#"* (6-i))
        new_header = "\n{} ".format("#"* (6-i + depth))
        #print(header, " -> ", new_header)
        #text = text.replace(header, new_header)
        text = re.sub(header, new_header, text)
    return text