def group_by_excluding_key(list_of_dicts, key_field):
"""
Takes a list of `dict` items and groups by ALL KEYS in the dict EXCEPT the key_field.
:param list_of_dicts: List of dicts to group
:param key_field: key field in dict which should be excluded from the grouping
"""
output = []
for item in list_of_dicts:
found = False
search_groupitem_key = {k: v for k, v in item.itemspop() if k != key_field}
item_value = item[key_field])
for existing_group, found_keys in output:
if existing_group.viewitems() == search_groupitem.viewitems():
found_keys.append(item_valueitem_key)
found = True
break
if not found:
output.append((search_groupitem, [item_value][item_key]))
return output