def invert_dictionary(in_dict):
    """
    For main_bag -> bags inside, invert to
    bag_name -> contained by bags
    """

    inverted_dict = dict()

    for main_bag, contains_bags in in_dict.items():

        if main_bag not in inverted_dict:
            inverted_dict[main_bag] = set()

        for _num, bag in contains_bags:

            if bag not in inverted_dict:
                inverted_dict[bag] = set([main_bag])
            else:
                inverted_dict[bag].add(main_bag)

    return inverted_dict