{ "info": { "author": "Leo Goodstadt", "author_email": "nested_dict@llew.org.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", "Intended Audience :: Financial and Insurance Industry", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Scientific/Engineering", "Topic :: Software Development", "Topic :: Software Development :: Libraries", "Topic :: Utilities" ], "description": ".. note ::\n\n * Source code at https://github.com/bunbun/nested-dict\n * Documentation at http://nested-dict.readthedocs.org\n\n##############################################################################\n``nested_dict``\n##############################################################################\n``nested_dict`` extends ``defaultdict`` to support python ``dict`` with multiple levels of nested-ness:\n\n*****************************************************************\nDrop in replacement for ``dict``\n*****************************************************************\n\n\n .. <>> from nested_dict import nested_dict\n >>> nd= nested_dict()\n >>> nd[\"one\"] = \"1\"\n >>> nd[1][\"two\"] = \"1 / 2\"\n >>> nd[\"uno\"][2][\"three\"] = \"1 / 2 / 3\"\n >>>\n ... for keys_as_tuple, value in nd.items_flat():\n ... print (\"%-20s == %r\" % (keys_as_tuple, value))\n ...\n ('one',) == '1'\n (1, 'two') == '1 / 2'\n ('uno', 2, 'three') == '1 / 2 / 3'\n\n ..\n Python\n\n Each nested level is created magically when accessed, a process known as \"auto-vivification\" in perl.\n\n\n******************************************************************************\nSpecifying the contained type\n******************************************************************************\n\n If you want the nested dictionary to hold\n * a collection (like the `set `__ in the first example) or\n * a scalar with useful default values such as ``int`` or ``str``.\n\n==============================\n*dict* of ``list``\\ s\n==============================\n .. <`__\\ s before iteration.\n\nYou do not need to know beforehand how many levels of nesting you have:\n\n .. <`__\\ ing for example).\n\nWe can convert to and from a vanilla python ``dict`` using\n * ``nested_dict.to_dict()``\n * ``nested_dict constructor``\n\n .. <>> from nested_dict import nested_dict\n >>> nd= nested_dict()\n >>> nd[\"one\"] = 1\n >>> nd[1][\"two\"] = \"1 / 2\"\n\n #\n # convert nested_dict -> dict and pickle\n #\n >>> nd.to_dict()\n {1: {'two': '1 / 2'}, 'one': 1}\n >>> import pickle\n >>> binary_representation = pickle.dumps(nd.to_dict())\n\n #\n # convert dict -> nested_dict\n #\n >>> normal_dict = pickle.loads(binary_representation)\n >>> new_nd = nested_dict(normal_dict)\n >>> nd == new_nd\n True\n\n ..\n Python\n\n\n##############################################################################\n``defaultdict``\n##############################################################################\n``nested_dict`` extends `collections.defaultdict `__\n\nYou can get arbitrarily-nested \"auto-vivifying\" dictionaries using `defaultdict `__.\n\n .. <