I'm -1 on adding it in stdlib.

But if it happens, I'm -1 on functools and collections.
They are used very much.  Every Python tool import them regardless how much
of their contents are used.

On the other hand, itertools contains random stuff very rarely used.

If you really want to add it in collections, I suggests
from collections.groupdict import GroupDict.

Regards,

On Tue, Jul 3, 2018 at 10:23 PM David Mertz <me...@gnosis.cx> wrote:

> Guido said he has mooted this discussion, so it's probably not reaching
> him.  It took one thousand fewer messages for him to stop following this
> than with PEP 572, for some reason :-).
>
> But before putting it on auto-archive, the BDFL said (1) NO GO on getting
> a new builtin; (2) NO OBJECTION to putting it in itertools.
>
> My problem with the second idea is that *I* find it very wrong to have
> something in itertools that does not return an iterator.  It wrecks the
> combinatorial algebra of the module.
>
> That said, it's easy to fix... and I believe independently useful.  Just
> make grouping() a generator function rather than a plain function.  This
> lets us get an incremental grouping of an iterable.  This can be useful if
> the iterable is slow or infinite, but the partial groupings are useful in
> themselves.
>
> Python 3.7.0 (default, Jun 28 2018, 07:39:16)
> [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from grouping import grouping
> >>> grouped = grouping('AbBa', key=str.casefold)
> >>> for dct in grouped: print(dct)
> ...
> {'a': ['A']}
> {'a': ['A'], 'b': ['b']}
> {'a': ['A'], 'b': ['b', 'B']}
> {'a': ['A', 'a'], 'b': ['b', 'B']}
>
>
> This isn't so useful for the concrete sequence, but for this it would be
> great:
>
> for grouped in grouping(data_over_wire()):
>
>     process_partial_groups(grouped)
>
>
> The implementation need not and should not rely on "pre-grouping" with
> itertools.groupby:
>
> def grouping(iterable, key=None):
>     groups = {}
>     key = key or (lambda x: x)
>     for item in iterable:
>         groups.setdefault(key(item), []).append(item)
>         yield groups
>
>
>
> --
> Keeping medicines from the bloodstreams of the sick; food
> from the bellies of the hungry; books from the hands of the
> uneducated; technology from the underdeveloped; and putting
> advocates of freedom in prisons.  Intellectual property is
> to the 21st century what the slave trade was to the 16th.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
INADA Naoki  <songofaca...@gmail.com>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to