r"""
    case where an item can belong to multiple groups

    Args:
        item_list (list):
        tags_list (list):

    Returns:
        dict: groupid_to_items

    CommandLine:
        python -m utool.util_dict --test-groupby_tags

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_dict import *  # NOQA
        >>> import utool as ut
        >>> tagged_item_list = {
        >>>     'spam': ['meat', 'protein', 'food'],
        >>>     'eggs': ['protein', 'food'],
        >>>     'cheese': ['dairy', 'protein', 'food'],
        >>>     'jam':  ['fruit', 'food'],
        >>>     'banana': ['weapon', 'fruit', 'food'],
        >>> }
        >>> item_list = list(tagged_item_list.keys())
        >>> tags_list = list(tagged_item_list.values())
        >>> groupid_to_items = groupby_tags(item_list, tags_list)
        >>> groupid_to_items = ut.map_vals(sorted, groupid_to_items)
        >>> result = ('groupid_to_items = %s' % (ut.repr4(groupid_to_items),))
        >>> print(result)
        groupid_to_items = {
            'dairy': ['cheese'],
            'food': ['banana', 'cheese', 'eggs', 'jam', 'spam'],
            'fruit': ['banana', 'jam'],
            'meat': ['spam'],
            'protein': ['cheese', 'eggs', 'spam'],
            'weapon': ['banana'],
        }

def groupby_tags(item_list, tags_list):
    r"""
    case where an item can belong to multiple groups

    Args:
        item_list (list):
        tags_list (list):

    Returns:
        dict: groupid_to_items

    CommandLine:
        python -m utool.util_dict --test-groupby_tags

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_dict import *  # NOQA
        >>> import utool as ut
        >>> tagged_item_list = {
        >>>     'spam': ['meat', 'protein', 'food'],
        >>>     'eggs': ['protein', 'food'],
        >>>     'cheese': ['dairy', 'protein', 'food'],
        >>>     'jam':  ['fruit', 'food'],
        >>>     'banana': ['weapon', 'fruit', 'food'],
        >>> }
        >>> item_list = list(tagged_item_list.keys())
        >>> tags_list = list(tagged_item_list.values())
        >>> groupid_to_items = groupby_tags(item_list, tags_list)
        >>> groupid_to_items = ut.map_vals(sorted, groupid_to_items)
        >>> result = ('groupid_to_items = %s' % (ut.repr4(groupid_to_items),))
        >>> print(result)
        groupid_to_items = {
            'dairy': ['cheese'],
            'food': ['banana', 'cheese', 'eggs', 'jam', 'spam'],
            'fruit': ['banana', 'jam'],
            'meat': ['spam'],
            'protein': ['cheese', 'eggs', 'spam'],
            'weapon': ['banana'],
        }

    """
    groupid_to_items = defaultdict(list)
    for tags, item in zip(tags_list, item_list):
        for tag in tags:
            groupid_to_items[tag].append(item)
    return groupid_to_items