Christopher Barker writes:

 > > If O(log N) is good enough and bijectivity is guaranteed by some
 > > other mechanism, a bisection search on d.items() with
 > > key=lambda x: x[1] does the trick.

 > You'd also have to keep it sorted by value.

I assumed you can do that with OrderedDict.  But yeah, it's a little
more complex.  Maybe some of these ideas are complex and useful enough
to deserve PyPI implementations, and if they prove to have corner
cases and get take up, then consideration for stdlib.

 > So now you are guaranteeing bijectivity and keeping it sorted --
 > I'd just use two dicts :-) Though then the values would have to be
 > hashable, so there's that.

Right (and I missed that throughout, so tyvm).  So much as the
"generic" theory of "low O" "bijection" is attractive, the
implementation details are application-specific.

Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2YV4C22IMTO5A7E3FJTZZ5QU2L7YPJAB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to