def group_policies_gen(flat_policies, config):
    'Filter policies using the following steps:\n    1. Apply prioritization among the policies that are sharing the same policy type and resource type\n    2. Remove redundant policies that may applicable across different types of resource\n    3. Filter policies based on type and return\n    :param flat_policies: list of flat policies\n    :return: Filtered policies\n    '
    filtered_policies = defaultdict(list)
    policy_name = []
    policies = [x for x in flat_policies if x[list(x.keys())[0]]['type']]
    priority = config.get('policy_info', {}).get('prioritization_attributes', {})
    aggregated_policies = dict()
    for plc in policies:
        attrs = [dot_notation(plc[list(plc.keys())[0]], dot_path) for key in priority.keys() for dot_path in priority[key]]
        attrs_list = [(x if isinstance(x, list) else [x]) for x in attrs]
        attributes = [(list_flatten(x) if isinstance(x, list) else x) for x in attrs_list]
        for y in itertools.product(*attributes):
            aggregated_policies.setdefault(y, [])
            aggregated_policies[y].append(plc)
    for key in aggregated_policies.keys():
        prioritized_policy = aggregated_policies[key][0]
        if (list(prioritized_policy.keys())[0] not in policy_name):
            filtered_policies[prioritized_policy[list(prioritized_policy.keys())[0]]['type']].append(prioritized_policy)
            policy_name.append(list(prioritized_policy.keys())[0])
    return filtered_policies
Filter policies using the following steps:
1. Apply prioritization among the policies that are sharing the same policy type and resource type
2. Remove redundant policies that may applicable across different types of resource
3. Filter policies based on type and return
:param flat_policies: list of flat policies
:return: Filtered policies
def group_policies_gen(flat_policies, config):
    'Filter policies using the following steps:\n    1. Apply prioritization among the policies that are sharing the same policy type and resource type\n    2. Remove redundant policies that may applicable across different types of resource\n    3. Filter policies based on type and return\n    :param flat_policies: list of flat policies\n    :return: Filtered policies\n    '
    filtered_policies = defaultdict(list)
    policy_name = []
    policies = [x for x in flat_policies if x[list(x.keys())[0]]['type']]
    priority = config.get('policy_info', {}).get('prioritization_attributes', {})
    aggregated_policies = dict()
    for plc in policies:
        attrs = [dot_notation(plc[list(plc.keys())[0]], dot_path) for key in priority.keys() for dot_path in priority[key]]
        attrs_list = [(x if isinstance(x, list) else [x]) for x in attrs]
        attributes = [(list_flatten(x) if isinstance(x, list) else x) for x in attrs_list]
        for y in itertools.product(*attributes):
            aggregated_policies.setdefault(y, [])
            aggregated_policies[y].append(plc)
    for key in aggregated_policies.keys():
        prioritized_policy = aggregated_policies[key][0]
        if (list(prioritized_policy.keys())[0] not in policy_name):
            filtered_policies[prioritized_policy[list(prioritized_policy.keys())[0]]['type']].append(prioritized_policy)
            policy_name.append(list(prioritized_policy.keys())[0])
    return filtered_policies