Why not `map(attrgetter('first_name'), all_names)`?
This one case is definitely nice. However...
What you've missed, in several examples is the value part of the tuple in your API. You've pulled out the key, and forgotten to include anything in the actual groups. I have a hunch that if your API were used, this would be a common pitfall.
I think this argues against your API and for Michael's that simply deals with "sequences of groupable things." That's much more like what one deals with in SQL, and is familiar that way. If the things grouped are compound object such as dictionaries, objects with common attributes, named tuples, etc. then the list of things in a group usually *does not* want the grouping attribute removed.
Good so far, but a lot of redundancy in always spelling tuple of `(derived-key, object)`.
And here you forget about the object itself 3 times in a row (or also forget some derived "value" that you might want in your other comments).
This is nice, and spelled correctly.
Yep.
I also think that the row-style "list of data" where you want to discard the key from the values is nicely spelled (in the PEP) as:
INDEX = 0
grouping(sequence, key=lambda row: row.pop(INDEX))
I agree this seems better as an implementation.
I agree still (after all, I proposed it to Michael). But this seems minor, and Guido seems not to like `collections` that much (or at least he commented on not using Counter ... which I personally love to use and to teach).
That said, a 'grouping()' function seems fine to me also... with a couple utility functions (that need not be builtin, or even standard library necessarily) in place of methods. A lot of what methods would do can easily be done using comprehensions as well, some examples are shown in the PEP.