from typing import Tuple
from typing import Dict
import re


def process_rule(rule: str) -> Tuple[str, Dict[str, int]]:
    """ for each rule, returns a (bag_color, internal_bags) representation."""
    # I couldn't find anything in Python that would be extremely complicated without using lookaheads it seems,
    # so I am employing a simple pipeline of splitting.
    temp_strings = (re.compile(" bag[s]*\.").split(rule))[0]
    temp_strings = re.compile(" bag[s]*, ").split(temp_strings)
    [bag_color, first_bag_string] = re.compile(" bags contain ").split(temp_strings[0])

    bag_strings = [first_bag_string] + temp_strings[1:]

    if bag_strings[0] == "no other":
        return bag_color, {}

    bags = {}
    for bag in bag_strings:
        amount = int(bag[0])
        color = bag[2:]
        bags[color] = amount
    return bag_color, bags