{ "info": { "author": "Thomas Kober", "author_email": "tttthomasssss@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "# ReversibleDict\n\n*~~~ A dictionary being able to perform a reverse lookup ~~~*\n\n## How does it work?\n\nI calculate a hash of the value (or a hash of the value's `__str__` representation for unhashable types - i.e. `lists`) and internally store the reverse mapping, so no linear search through the values if you thought about that.\n\n## What if there is more than 1 value for a key?\n\nI simply return a `list` of all keys that matched. \n\n## Usage\n```\n>>> from reversibledict import ReversibleDict\n>>> r = ReversibleDict()\n>>> r['a'] = 1\n>>> r['b'] = 2\n>>> r['c'] = 1\n>>> r\n{'a': 1, 'c': 1, 'b': 2}\n>>> r.key_for_value(2)\n'b'\n>>> r.key_for_value(1)\n['a', 'c']\n>>> r.key_for_value(666) == None\nTrue\n```\n\nIt can also deal with unhashable types such as `lists`:\n\n```\n>>> from reversibledict import ReversibleDict\n>>> r = ReversibleDict()\n>>> r['a'] = [1,2,3]\n>>> r['b'] = [3,2,1]\n>>> r['c'] = [1]\n>>> r['d'] = [1,2,3]\n>>> r\n{'a': [1, 2, 3], 'c': [1], 'b': [3, 2, 1], 'd': [1, 2, 3]}\n>>> r.key_for_value([1,2,3])\n['a', 'd']\n>>> r.key_for_value([3,2,1])\n'b'\n>>> r.key_for_value([]) == None\nTrue\n\n```\n\nIf you don't like the inconsistency that it is returning a `list` if there is more than 1 matching value, `None` if there is no matching value and a scalar if there is exactly 1 matching value then you can do the following:\n\n```\n>>> from reversibledict import ReversibleDict\n>>> r = ReversibleDict(reverse_as_list=True)\n>>> r['a'] = 1\n>>> r['b'] = 2\n>>> r['c'] = 1\n>>> r\n{'a': 1, 'c': 1, 'b': 2}\n>>> r.key_for_value(2)\n['b']\n>>> r.key_for_value(1)\n['a', 'c']\n>>> r.key_for_value(666)\n[]\n```", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tttthomasssss/reversibledict", "keywords": "dict reversible-dict value-lookup", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "reversibledict", "package_url": "https://pypi.org/project/reversibledict/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/reversibledict/", "project_urls": { "Homepage": "https://github.com/tttthomasssss/reversibledict" }, "release_url": "https://pypi.org/project/reversibledict/0.1.0/", "requires_dist": [ "check-manifest; extra == 'dev'", "coverage; extra == 'test'" ], "requires_python": "", "summary": "Reversible dict", "version": "0.1.0" }, "last_serial": 2801516, "releases": { "0.1.0": [] }, "urls": [] }