_______________________________________________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@gmail.com> wrote:On 1 July 2018 at 06:18, Chris Barker via Python-ideas <python-ideas@python.org> wrote:I'm really warming to the:Alternate: collections.Groupingversion -- 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 thatwould make this configurable? Something like:from collections import Groupingdeps = Grouping(set) # list can be the defaultdeps.update(other_deps) # uses set.update or list.extend for every keydeps.add(trigger, target) # uses set.add or list.appendyeah, 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@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@noaa.gov
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/