How to implement an efficient bidirectional hash table?
问题 Python dict is a very useful data-structure: d = {\'a\': 1, \'b\': 2} d[\'a\'] # get 1 Sometimes you\'d also like to index by values. d[1] # get \'a\' Which is the most efficient way to implement this data-structure? Any official recommend way to do it? 回答1: Here is a class for a bidirectional dict , inspired by Finding key from value in Python dictionary and modified to allow the following 2) and 3). Note that : 1) The inverse directory bd.inverse auto-updates itself when the standard dict