Re: [Python-ideas] grouping / dict of lists

2018-07-18 Thread Michel Desmoulin
Counter also consider any missing key has the value "0". With the constructor (accepting any iterable) and the most_common(n), it's just a very set of features if you need to count anything. Le 13/07/2018 à 19:45, Michael Selik a écrit : > On Mon, Jul 2, 2018 at 8:49 AM Chris Barker

Re: [Python-ideas] grouping / dict of lists

2018-07-13 Thread Michael Selik
On Mon, Jul 2, 2018 at 8:49 AM Chris Barker wrote: > On Fri, Jun 29, 2018 at 11:25 PM, Guido van Rossum > wrote: > > >> Hm, this actually feels heavier to me. But then again I never liked or >> understood the need for Counter -- >> > > actually, me neither -- and partly because it's too

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Michael Selik
On Tue, Jul 3, 2018, 6:32 PM Steven D'Aprano wrote: > On Tue, Jul 03, 2018 at 10:33:55AM -0700, Chris Barker wrote: > > On Tue, Jul 3, 2018 at 8:33 AM, Steven D'Aprano > wrote: > > > > > but why are we using key values by hand when grouping ought to do it > for > > >> us, as Michael Selik's

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Steven D'Aprano
On Tue, Jul 03, 2018 at 10:33:55AM -0700, Chris Barker wrote: > On Tue, Jul 3, 2018 at 8:33 AM, Steven D'Aprano wrote: > > > but why are we using key values by hand when grouping ought to do it for > >> us, as Michael Selik's version does? > > > > grouping(words, key=len) > > > because

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Greg Ewing
MRAB wrote: I think that building an iterable of 2-tuples to pass to 'grouped' is much like following a decorate-sort-undecorate pattern when sorting, or something similar when using 'min' or 'max'. Passing an iterable of items and optionally a key function is simpler, IMHO. It should

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread MRAB
On 2018-07-03 23:20, Greg Ewing wrote: Nicolas Rolin wrote: grouping(((len(word), word) for word in words)) That actually has one more level of parens than are needed, you can just write grouping((len(word), word) for word in words) FWIW, here's my opinion. I much prefer something

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Greg Ewing
Nicolas Rolin wrote: grouping(((len(word), word) for word in words)) That actually has one more level of parens than are needed, you can just write grouping((len(word), word) for word in words) -- Greg ___ Python-ideas mailing list

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Chris Barker via Python-ideas
On Tue, Jul 3, 2018 at 8:33 AM, Steven D'Aprano wrote: > but why are we using key values by hand when grouping ought to do it for > us, as Michael Selik's version does? > > grouping(words, key=len) because supplying a key function is sometimes cleaner, and sometimes uglier than building up

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Steven D'Aprano
On Fri, Jun 29, 2018 at 10:53:34AM -0700, Michael Selik wrote: > Hello, > > I've drafted a PEP for an easier way to construct groups of elements from a > sequence. https://github.com/selik/peps/blob/master/pep-.rst Seems useful, but I suggest that since it has to process the entire data set

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Steven D'Aprano
On Tue, Jul 03, 2018 at 04:12:14PM +0200, Nicolas Rolin wrote: > I agree the examples have lisp-level of brackets. However by using the fact > tuples don't need brackets and the fact we can use a list instead of an > iterable (the grouper will have to stock the whole object in memory anyway, >

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Nicolas Rolin
2018-07-03 14:58 GMT+02:00 David Mertz : > On Tue, Jul 3, 2018 at 2:52 AM Chris Barker via Python-ideas > > 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

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread David Mertz
On Tue, Jul 3, 2018 at 2:52 AM Chris Barker via Python-ideas < python-ideas@python.org> wrote: > I'd write: >> > map(len, words) >> >> But I'd also write >> [len(fullname) for fullname in contacts] >> > > map(lambda name: name.first_name, all_names) > vs > [name.first_name for nam in all

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Chris Barker via Python-ideas
On Mon, Jul 2, 2018 at 11:50 PM, Chris Barker wrote: > - keep the key function optional parameter. > - add a value function optional parameter. -- it really makes any case > where you don't want to store the whole item a lot easier. > > - Have the default key function be itemgetter(0) and the

Re: [Python-ideas] grouping / dict of lists

2018-07-03 Thread Chris Barker via Python-ideas
On Mon, Jul 2, 2018 at 9:39 AM, Michael Selik wrote: > On Mon, Jul 2, 2018 at 2:32 AM Nicolas Rolin >>> wrote: >>> For example the default could be such that grouping unpack tuples (key, value) from the iterator and do what's expected with it (group value by key). It is quite

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Guido van Rossum
On Mon, Jul 2, 2018 at 12:50 AM Michael Selik wrote: > > [Guido] > >> You'll never get consensus on anything here, but you have my blessing for >> this without consensus. >> > > That feels like a success, but I'm going to be a bit more ambitious and > try to persuade you that `grouping` belongs

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Michael Selik
> > On Mon, Jul 2, 2018 at 2:32 AM Nicolas Rolin >> wrote: >> >>> For example the default could be such that grouping unpack tuples (key, >>> value) from the iterator and do what's expected with it (group value by >>> key). It is quite reasonable, and you have one example with (key, value) in >>>

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Steven D'Aprano
On Mon, Jul 02, 2018 at 02:52:03AM -0700, Michael Selik wrote: > Third, some classes might have a rich equality method that allows many > interesting values to all wind up in the same group even if using the > default "identity" key-function. I would expect an identity key function to group by

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Nicolas Rolin
My question would be : does it have to be a key function ? Can't we just remove the "key" argument ? Because for pretty much all the given examples, I would find my default as readable and nearly as short as the "key" syntax : > grouping(words, key=len) grouping((len(word), word for word in

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Michael Selik
On Mon, Jul 2, 2018 at 2:52 AM Michael Selik wrote: > On Mon, Jul 2, 2018 at 2:32 AM Nicolas Rolin > wrote: > >> I think the current default quite weird, as it pretty much account to a >> count() of each key (which can be useful, but not really what I except from >> a grouping). I would prefer

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Michael Selik
On Mon, Jul 2, 2018 at 2:32 AM Nicolas Rolin wrote: > I think the current default quite weird, as it pretty much account to a > count() of each key (which can be useful, but not really what I except from > a grouping). I would prefer a default that might return an error to a > default that says

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Nicolas Rolin
I think the current default quite weird, as it pretty much account to a count() of each key (which can be useful, but not really what I except from a grouping). I would prefer a default that might return an error to a default that says ok and output something that is not what I might want. For

Re: [Python-ideas] grouping / dict of lists

2018-07-02 Thread Michael Selik
I made some heavy revisions to the PEP. Linking again for convenience. https://github.com/selik/peps/blob/master/pep-.rst Replying to Guido, Nick, David, Chris, and Ivan in 4 sections below. [Guido] On Fri, Jun 29, 2018 at 11:25 PM Guido van Rossum wrote: > On Fri, Jun 29, 2018 at 3:23 PM

Re: [Python-ideas] grouping / dict of lists

2018-07-01 Thread Nick Coghlan
On 1 July 2018 at 15:18, Chris Barker via Python-ideas wrote: > On Fri, Jun 29, 2018 at 10:53 AM, Michael Selik wrote: >> >> I've drafted a PEP for an easier way to construct groups of elements from >> a sequence. https://github.com/selik/peps/blob/master/pep-.rst >> > I'm really warming to

Re: [Python-ideas] grouping / dict of lists

2018-06-30 Thread Chris Barker via Python-ideas
On Fri, Jun 29, 2018 at 10:53 AM, Michael Selik wrote: > I've drafted a PEP for an easier way to construct groups of elements from > a sequence. https://github.com/selik/peps/blob/master/pep-.rst > > I'm really warming to the: Alternate: collections.Grouping version -- I really like this

Re: [Python-ideas] grouping / dict of lists

2018-06-30 Thread Nick Coghlan
On 30 June 2018 at 16:25, Guido van Rossum wrote: > On Fri, Jun 29, 2018 at 3:23 PM Michael Selik wrote: >> I included an alternate solution of a new class, collections.Grouping, >> which has some advantages. In addition to having less of that "heavy-handed" >> feel to it, the class can have a

Re: [Python-ideas] grouping / dict of lists

2018-06-30 Thread Serhiy Storchaka
30.06.18 00:42, Guido van Rossum пише: On a quick skim I see nothing particularly objectionable or controversial in your PEP, except I'm unclear why it needs to be a class method on `dict`. Adding something to a builtin like this is rather heavy-handed. Is there a really good reason why it

Re: [Python-ideas] grouping / dict of lists

2018-06-30 Thread Guido van Rossum
On Fri, Jun 29, 2018 at 3:23 PM Michael Selik wrote: > On Fri, Jun 29, 2018 at 2:43 PM Guido van Rossum wrote: > >> On a quick skim I see nothing particularly objectionable or controversial >> in your PEP, except I'm unclear why it needs to be a class method on `dict`. >> > > Since it

Re: [Python-ideas] grouping / dict of lists

2018-06-29 Thread Michael Selik
On Fri, Jun 29, 2018 at 2:43 PM Guido van Rossum wrote: > On a quick skim I see nothing particularly objectionable or controversial > in your PEP, except I'm unclear why it needs to be a class method on `dict`. > Since it constructs a basic dict, I thought it belongs best as a dict constructor

Re: [Python-ideas] grouping / dict of lists

2018-06-29 Thread Guido van Rossum
On a quick skim I see nothing particularly objectionable or controversial in your PEP, except I'm unclear why it needs to be a class method on `dict`. Adding something to a builtin like this is rather heavy-handed. Is there a really good reason why it can't be a function in `itertools`? (I don't

Re: [Python-ideas] grouping / dict of lists

2018-06-29 Thread Michael Selik
Hello, I've drafted a PEP for an easier way to construct groups of elements from a sequence. https://github.com/selik/peps/blob/master/pep-.rst As a teacher, I've found that grouping is one of the most awkward tasks for beginners to learn in Python. While this proposal requires understanding