mcfc

A tool to create multiple-choice flashcards more efficiently.

import re import js def read_multiline_strings_from_file(text): # Split the string into a list of multiline strings multiline_strings = re.split(r"[\n\r]+\d+.", text) multiline_strings[0] = multiline_strings[0].replace("1.", "") for multiline_string in range(len(multiline_strings)): # Remove extra whitespace from the beginning and end of each multiline string multiline_strings[multiline_string] = multiline_strings[multiline_string].strip() # Remove all tab characters from each multiline string multiline_strings[multiline_string] = multiline_strings[multiline_string].replace("\t", " ") # Replace "\s(?=[A-Za-z]\))" with "\n(?=[A-Za-z]\))" multiline_strings[multiline_string] = re.sub(r"\s(?=[A-Za-z]\))", r"\n", multiline_strings[multiline_string]) multiline_strings[multiline_string] = re.sub(r"(?<=\n[A-Za-z])\)", r".", multiline_strings[multiline_string]) # Remove multiple newlines multiline_strings[multiline_string] = re.sub(r"\n\s*\n", r"\n", multiline_strings[multiline_string]) # Return the list of multiline strings return multiline_strings def parse_answers(text): lines = text.splitlines() # Loop all each line in the file, and add the first letter in the line to the list of answers if it's not empty answers = [] for line in lines: if line.strip() != "": # Get the first character in the line that's either an uppercase or lowercase letter # Output: "A" or "a" first_letter = re.search(r"[A-Za-z]", line).group(0) # Add the first letter to the list of answers answers.append(first_letter) # Return the list of answers return answers def show_output(): input_questions = Element("mcq_box") input_answers = Element("mca_box") questions = read_multiline_strings_from_file(input_questions.element.value) answers = parse_answers(input_answers.element.value) output = "" for i in range(len(questions)): output += questions[i] output += "\n\n" output += answers[i] output += "\n\n\n" output_box = Element("mco") output_box.write(output)
Where did mcfc come from? This is based on the Python script I used to convert dumps of multiple-choice questions into a format that can be imported easily into Quizlet.
How does it work?