from typing import List
from typing import Dict
from typing import Tuple
import re


def convert(day_input: List[str]) -> Dict[str, List[Tuple[int, str]]]:
    """Converts the input to a dict mapping each key to a list of its contents,
    where each content element is represented as a tuple of quantity and element"""
    d: Dict[str, List[Tuple[int, str]]] = dict()
    for line in day_input:
        # Remove all superfluous text and split the spec
        spec_split = re.sub(r" bags?|\.", "", line).split(" contain ")
        key = spec_split[0]
        d[key] = []
        for elem in spec_split[1].split(", "):
            elem_split = elem.split(" ", 1)
            if (elem_split[0].isnumeric()):
                d[key].append((int(elem_split[0]), elem_split[1]))
    return d