Package: dicter
dicteris Python package with advanced dictionary functions:Traverse through nested dicts to retrieve key-path.Set value in dictionary using key-pathGet value in dictionary using key-path.Flattens dicts.Compare two dicts.Store and load in json.Star this repo if you like it! ⭐️Documentationdicter documentation pages (Sphinx)InstallationInstall dicter from PyPI (recommended). dicter is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows.A new environment can be created as following:pipinstall-UdicterAlternatively, you can install from the GitHub source:# Directly install from github sourcepipinstallgit+https://github.com/erdogant/dicterExamplesImport dicter packageimportdicterasdtTraverse all paths in dictionary.importdicterasdt# Example dict:d={'level_a':1,'level_b':{'a':'hello world'},'level_c':3,'level_d':{'a':1,'b':2,'c':{'e':10}},'level_e':2}# Walk through dict to get all pathspaths=dt.traverse(d)print(paths)# [[['level_a'], 1],# [['level_c'], 3],# [['level_e'], 2],# [['level_b', 'a'], 'hello world'],# [['level_d', 'a'], 1],# [['level_d', 'b'], 2],# [['level_d', 'c', 'e'], 10]]Get value from dictionary using nested keys.# Import dicterimportdicterasdt# Example dictionaryd={'level_a':1,'level_b':{'a':'hello world'},'level_c':3,'level_d':{'a':1,'b':2,'c':{'e':10}},'level_e':2}# Get the value for the nested path for:value=dt.get_nested(d,key_path=["level_b","a"])print(value)# 'hello world'Set value from dictionary using nested keys.# Import dicterimportdicterasdt# Example: New path and value in dictionary.d={}key_path=['person','address','city']dt.set_nested(d,key_path,'New York')# Print updated dictionaryprint(d)# {'person': {'address': {'city': 'New York'}}}Set value from dictionary using nested keys.# Import dicterimportdicterasdt# Example dictd={'level_a':1,'level_b':{'a':'hello world'},'level_c':3,'level_d':{'a':1,'b':2,'c':{'e':10}},'level_e':2}# Flatten dictionarydflat=dt.flatten(d)print(d_flat)# [['level_a', 1],#  ['a', 'hello world'],#  ['level_c', 3],#  ['a', 1],#  ['b', 2],#  ['e', 10],#  ['level_e', 2]]Depth of dictionary.# Import dicterimportdicterasdtd={'level_a':1,'level_b':{'a':'hello world'},'level_c':3,'level_d':{'a':1,'b':2,'c':{'e':10}},'level_e':2}n=dt.depth(d)Compare dictionary.# Import dicterimportdicterasdtExample:Addd1={'level_a':1,'level_b':{'a':'hello world'},'level_c':'new in d2'}d2={'level_a':1,'level_b':{'a':'hello world'}}out=dt.compare(d1,d2)print(out)Example:Removed1={'level_a':1,'level_b':{'a':'hello world'}}d2={'level_a':1,'level_b':{'a':'hello world'},'level_c':'new in d2'}out=dt.compare(d1,d2)print(out)Example:Modifiedd1={'level_a':1,'level_b':{'a':'hello world'}}d2={'level_a':1,'level_b':{'a':'modified'}}out=dt.compare(d1,d2)print(out['modified'])Save and load dictionary.# Import dicterimportdicterasdtd={'level_a':None,'level_b':{'a':'hello world'},'level_c':True,'level_d':2.3,'level_e':[[1,2,3],[1,2]]}filepath='c:/temp/test/dicter_save.json'# First savedt.save(d,filepath=filepath,overwrite=True)# Loadd=dt.load(filepath)GeneralReferenceshttps://github.com/erdogant/dicterCitationPlease cite in your publications if this is useful for your research (see citation).MaintainersErdogan Taskesen, github:erdogantContributeAll kinds of contributions are welcome!If you wish to buy me aCoffeefor this work, it is very appreciated :)LicenceSeeLICENSEfor details.