[Python-ideas] Dict with inverse form

Andrew Barnert abarnert at yahoo.com
Fri Feb 12 15:27:08 EST 2016


On Feb 12, 2016, at 05:27, João Bernardo <jbvsmo at gmail.com> wrote:
> 
> 
>> On Fri, Feb 12, 2016 at 2:07 AM, Andrew Barnert <abarnert at yahoo.com> wrote:
>> For example, when I've built something like this, sometimes I want errors on duplicate values, sometimes just pick one arbitrarily, sometimes I want the inverse dict to store sets of values, and sometimes I even want _both_ to store sets of values. Do you want to do just one of those, or two or more? Controlled by flags? Or different attribute names? Or different classes?
> 
> My use case is quite simple. I believe I always used this pattern on a one-to-one mapping, so allowing repeated values to overwrite or throwing an error is not exactly important to me, but it may be to someone else.
> 
> Someone suggested a MultiDict sort of thing, but I don't think I need that amount of complexity here.
> 
> I will write a concrete class and post on PyPI then.

I look forward to it. Next time I need some variation of this, even if it *isn't* the same variation you end up building, the fact that there's a potential de facto standard for what to call the ".inv" or whatever still helps me, right?

Also, even if nobody ever agrees to put this in the stdlib, the collections module linked to some outside recipes/modules like OrderedSet long before Nick and the other packaging guys started pushing the idea that it was a good idea for the stdlib in general. I think if this gets sufficient uptake, it deserves such a link. As you say, it's something many people end up building for themselves.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160212/49d34892/attachment-0001.html>


More information about the Python-ideas mailing list