def add_intersection_complement(result, sym_set, **flags):
    final_result = []
    for res in result:
        res_copy = res
        for (key_res, value_res) in res.items():
            intersection_true = flags.get('Intersection', True)
            complements_true = flags.get('Complement', True)
            for (key_sym, value_sym) in sym_set.items():
                if (key_sym == key_res):
                    if intersection_true:
                        new_value = Intersection(FiniteSet(value_res), value_sym)
                        if (new_value is not S.EmptySet):
                            res_copy[key_res] = new_value
                    if complements_true:
                        new_value = Complement(FiniteSet(value_res), value_sym)
                        if (new_value is not S.EmptySet):
                            res_copy[key_res] = new_value
        final_result.append(res_copy)
    return final_result
def add_intersection_complement(result, sym_set, **flags):
    final_result = []
    for res in result:
        res_copy = res
        for (key_res, value_res) in res.items():
            intersection_true = flags.get('Intersection', True)
            complements_true = flags.get('Complement', True)
            for (key_sym, value_sym) in sym_set.items():
                if (key_sym == key_res):
                    if intersection_true:
                        new_value = Intersection(FiniteSet(value_res), value_sym)
                        if (new_value is not S.EmptySet):
                            res_copy[key_res] = new_value
                    if complements_true:
                        new_value = Complement(FiniteSet(value_res), value_sym)
                        if (new_value is not S.EmptySet):
                            res_copy[key_res] = new_value
        final_result.append(res_copy)
    return final_result