[Python-ideas] Fwd: grouping / dict of lists
Chris Barker
chris.barker at noaa.gov
Sun Jul 1 20:45:51 EDT 2018
Ivan,
Did you mean this to go to the list? I hope so, as I've cc-d it this time
:-)
On Sun, Jul 1, 2018 at 1:20 AM, Ivan Levkivskyi <levkivskyi at gmail.com>
wrote:
> On 1 July 2018 at 06:18, Chris Barker via Python-ideas <
> python-ideas at python.org> wrote:
>
>> I'm really warming to the:
>>
>> Alternate: collections.Grouping
>>
>> version -- I really like this as a kind of custom mapping, rather than
>> "just a function" (or alternate constructor) --
>>
>
I wanted the group to be represented as a set, not a list. I however
> understand that list may be more common. Can we design an API that
> would make this configurable? Something like:
>
> from collections import Grouping
>
> deps = Grouping(set) # list can be the default
> deps.update(other_deps) # uses set.update or list.extend for every key
> deps.add(trigger, target) # uses set.add or list.append
>
yeah, I thought about that too -- Michael was using set() in some of his
examples.
But the question is -- do we have a single switchable version or just too
classes?
> Probably allowing an arbitrary collection for values is to general/hard.
>
maybe not -- if we had the criteria that you pass in any collection you
wanted, as long as it had either an .append() or .add()method, it would be
pretty easy to do with duck typing magic.
Sure -- a user could make a mess easily enough by passing in a weird custom
class, but so what? Using something other than a set or list would be a "at
your own risk" thing anyway.
> Maybe we can just add a flag `unique=True` to the constructor, that will
> cause using sets instead of lists for groups?
>
That's another, more robust, but less flexible option.
Stay tuned for a prototype, if I can get it done fast....
-CHB
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
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
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
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/20180701/c2cd3d60/attachment.html>
More information about the Python-ideas
mailing list