the other restriction is that both keys and values (or is it values and keys?) both need to be immutable.

but yes, I've needed this a lot, and I think that fact that both sets of keys need to be unique isn't really a restriction -- if you need to look it up either way, then it's probably naturally a one-to-one mapping anyway.

I've needed this a few times, and have always kludged something together, rather than make a proper, robust tested class. So I look forward to seeing what you come up with.

-CHB




On Fri, Feb 12, 2016 at 5:27 AM, João Bernardo <jbvsmo@gmail.com> wrote:

On Fri, Feb 12, 2016 at 2:07 AM, Andrew Barnert <abarnert@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.

João Bernardo


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



--

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