bidict
The bidirectional mapping library for Python.
bidict:
- has been used for many years by several teams at Google, Venmo, CERN, Bank of America Merrill Lynch, Bloomberg, Two Sigma, and many others
- has carefully designed APIs for safety, simplicity, flexibility, and ergonomics
- is fast, lightweight, and has no runtime dependencies other than Python's standard library
- integrates natively with Python’s
collections.abc
interfaces - provides type hints for all public APIs
- is implemented in concise, well-factored, pure (PyPy-compatible) Python code that is optimized for running efficiently as well as for reading and learning [1]
- has extensive docs and test coverage (including property-based tests and benchmarks) run continuously on all supported Python versions
Installation
pip install bidict
Quick Start
>>> from bidict import bidict
>>> element_by_symbol = bidict({'H': 'hydrogen'})
>>> element_by_symbol['H']
'hydrogen'
>>> element_by_symbol.inverse['hydrogen']
'H'