Steven: You've misunderstood part of the discussion. There are two different signatures being discussed/proposed for a grouping() function.
The one you show we might call grouping_michael(). The alternate API we might call grouping_chris(). These two calls will produce the same result (the first output you show) grouping_michael(words, keyfunc=len) grouping_chris((len(word), word) for word in words) I happen to prefer grouping_michael(), but recognize they each make slightly different things obvious. Absolutely no one wants the behavior in your second output. On Tue, Jul 3, 2018, 9:32 PM Steven D'Aprano <st...@pearwood.info> wrote: > Of course you can prepare the sequence any way you like, but these are > not equivalent: > > grouping(words, keyfunc=len) > grouping((len(word), word) for word in words) > > The first groups words by their length; the second groups pairs of > (length, word) tuples by equality. > > py> grouping("a bb ccc d ee fff".split(), keyfunc=len) > {1: ['a', 'd'], 2: ['bb', 'ee'], 3: ['ccc', 'fff']} > > py> grouping((len(w), w) for w in "a bb ccc d ee fff".split()) > {(3, 'ccc'): [(3, 'ccc')], (1, 'd'): [(1, 'd')], (2, 'ee'): [(2, 'ee')], > (3, 'fff'): [(3, 'fff')], (1, 'a'): [(1, 'a')], (2, 'bb'): [(2, ' >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/