import re


def format_imports(text):
    """
    Takes a string of text and formats it based on rule 3 (see docs).
    """
    # rule to find consective imports
    regex4 = r"^import[\s\w]+?(?=from|^\s*$)"

    # this subsitution will happen with a function
    def subst4(match_obj):
        pattern = r"import (\w+)"
        ind_imports = re.findall(pattern, match_obj.group(0))
        return r"import " + ", ".join(ind_imports) + "\n"

    text = re.sub(regex4, subst4, text, 0, re.MULTILINE)
    # return formatted text
    return text