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
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
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
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
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
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
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
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
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
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,
>
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
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
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
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
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
>
> 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
>>>
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
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
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
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
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
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
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
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
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
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
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
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
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
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
30 matches
Mail list logo