def get_bags_contain_input(rules, color):
    """ Returns a set of bags that contain the bag of the specified color.

    Solved with a stack.
    :param rules: rules
    :param color: color of bag
    :return: set
    """
    bags = set()
    stack = [color]

    # implementation with a stack
    while len(stack) > 0:
        for item in stack:
            # remove item from stack
            stack.remove(item)
            # iterate over all rules to find the right bags
            for key, value in rules.items():
                if value is None:
                    continue
                # if bag contains wanted bag add to stack and output set
                if item in value.keys():
                    bags.add(key)
                    stack.append(key)

    return bags