* There are some nice advantages in flexibility to having a Grouping class, rather than simply a function.
So this ended up a long post, so the TL;DR
* There are types of data well suited to the key function approach, and other data not so well suited to it. If you want to support the not as well suited use cases, you should have a value function as well and/or take a (key, value) pair.
So: I propose a best of all worlds version: a Grouping class (subclass of dict):
* The constructor takes an iterable of (key, value) pairs by default.
* The constructor takes an optional key_func -- when not None, it is used to determine the keys in the iterable instead.
* The constructor also takes a value_func -- when specified, it processes the items to determine the values.
* a_grouping[key] = value
adds the value to the list corresponding to the key.
* a_grouping.add(item) -- applies the key_func and value_func to add a new value to the appropriate group.
Now the lengthy commentary and examples: