[Python-ideas] Fwd: grouping / dict of lists
Chris Barker
chris.barker at noaa.gov
Thu Jul 5 01:23:38 EDT 2018
On Wed, Jul 4, 2018 at 6:34 AM, David Mertz <mertz at gnosis.cx> wrote:
> 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.
>
I starting thinking grouping_chris was the obvious and natural thing to do,
but his discussion has made it clear that grouping_michael is more natural
for some kinds of data.
and in some cases, it really comes down to taste, after all, who's to say
which of these is "better"
map(func, iterable)
or
(expression for item in iterable)
given that map existed in Python when comprehensions were added, I tend to
see the latter as more "Pythonic" but that's just me.
So I'm currently lobbying for both :-)
The default is iterable of (key. value) pairs, but the use can specify a
key function is they want to do it that way.
While a bit of a schizophrenic API, it makes sens (to me), because
grouping_mikael isn't useful with a default key function anyway.
The other enhancement I suggest is that an (optional) value function be
added, as there are use cases where that would be really helpful.
-CHB
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180704/45fdd987/attachment.html>
More information about the Python-ideas
mailing list