import re


def parse_questions_X(questions_X_content: str) -> dict:
    """
    Parses a "questions-X.txt" (where X is 'words' or 'phrases') file into a
    section-separated dictionary for looking up word pairs from each section.

    Parameters
    ----------
    questions_X_content: str
        Raw content of the "questions-X.txt" (where X is 'words' or 'phrases') file

    Returns
    -------
    questions_X: dict
        Dictionary mapping from section to a list of word pairs
    """
    # Parse questions 'X' pairs for each section
    questions_X_sections = re.findall(r"(: .+)", questions_X_content)
    questions_X_delimiters = "|".join(questions_X_sections)

    # Split questions 'X' content into list
    questions_X_content_splits = []
    for content_split in re.split(questions_X_delimiters, questions_X_content):
        if len(content_split) == 0:
            continue

        content_split_lines = content_split[1 : len(content_split) - 1].split("\n")

        questions_X_split_content: list = []
        for word_line in content_split_lines:

            # Split string of words into tuple of lower-case words and append to list
            words = word_line.split()
            words_tuple = tuple([word.lower() for word in words])
            questions_X_split_content.append(words_tuple)
        questions_X_content_splits.append(questions_X_split_content)

    # Construct dictionary with question-X entries
    questions_X = {
        questions_X_sections[i][2:]: questions_X_content_splits[i]
        for i in range(len(questions_X_sections))
    }

    return questions_X