dicter

Python package with advanced dictionary functions. Traverse through nested dicts. Set and get multiple keys. Flattens dicts. Store and load in json and more!

https://github.com/erdogant/dicter

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.2%) to scientific vocabulary

Keywords

compare compare-data dictionary flatten json load nested save traversal
Last synced: 6 months ago · JSON representation ·

Repository

Python package with advanced dictionary functions. Traverse through nested dicts. Set and get multiple keys. Flattens dicts. Store and load in json and more!

Basic Info
  • Host: GitHub
  • Owner: erdogant
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 6.67 MB
Statistics
  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 8
Topics
compare compare-data dictionary flatten json load nested save traversal
Created about 3 years ago · Last pushed 10 months ago
Metadata Files
Readme Changelog Funding License Citation

README.md

Python Pypi Docs LOC Downloads Downloads License Forks Issues Project Status DOI GitHub Repo stars GitHub repo size Donate <!---BuyMeCoffee--> <!---Coffee-->

  • dicter is Python package with advanced dictionary functions:

    • Traverse through nested dicts to retrieve key-path.
    • Set value in dictionary using key-path
    • Get value in dictionary using key-path.
    • Flattens dicts.
    • Compare two dicts.
    • Store and load in json.

Star this repo if you like it! ⭐️

Documentation

Installation

  • Install 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:

bash pip install -U dicter

  • Alternatively, you can install from the GitHub source: bash # Directly install from github source pip install git+https://github.com/erdogant/dicter

Examples

Import dicter package

python import dicter as dt

Traverse all paths in dictionary.

```python import dicter as dt # Example dict: d = {'levela': 1, 'levelb': {'a': 'hello world'}, 'levelc': 3, 'leveld': {'a': 1, 'b': 2, 'c': {'e': 10}}, 'level_e': 2}

Walk through dict to get all paths

paths = 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.

```python

Import dicter

import dicter as dt

Example dictionary

d = {'levela': 1, 'levelb': {'a': 'hello world'}, 'levelc': 3, 'leveld': {'a': 1, 'b': 2, 'c': {'e': 10}}, 'level_e': 2}

Get the value for the nested path for:

value = dt.getnested(d, keypath=["level_b", "a"]) print(value)

'hello world'

```

Set value from dictionary using nested keys.

```python

Import dicter

import dicter as dt

Example: New path and value in dictionary.

d = {} keypath = ['person', 'address', 'city'] dt.setnested(d, key_path, 'New York')

Print updated dictionary

print(d)

{'person': {'address': {'city': 'New York'}}}

```

Set value from dictionary using nested keys.

```python

Import dicter

import dicter as dt

Example dict

d = {'levela': 1, 'levelb': {'a': 'hello world'}, 'levelc': 3, 'leveld': {'a': 1, 'b': 2, 'c': {'e': 10}}, 'level_e': 2}

Flatten dictionary

dflat = 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.

```python

Import dicter

import dicter as dt

d = {'levela': 1, 'levelb': {'a': 'hello world'}, 'levelc': 3, 'leveld': {'a': 1, 'b': 2, 'c': {'e': 10}}, 'level_e': 2} n = dt.depth(d)

```

Compare dictionary.

```python

Import dicter

import dicter as dt

Example: Add d1 = {'levela': 1, 'levelb': {'a': 'hello world'}, 'levelc': 'new in d2'} d2 = {'levela': 1, 'level_b': {'a': 'hello world'}} out = dt.compare(d1, d2) print(out)

Example: Remove d1 = {'levela': 1, 'levelb': {'a': 'hello world'}} d2 = {'levela': 1, 'levelb': {'a': 'hello world'}, 'level_c': 'new in d2'} out = dt.compare(d1, d2) print(out)

Example: Modified d1 = {'levela': 1, 'levelb': {'a': 'hello world'}} d2 = {'levela': 1, 'levelb': {'a': 'modified'}} out = dt.compare(d1, d2) print(out['modified'])

```

Save and load dictionary.

```python

Import dicter

import dicter as dt

d = {'levela': None, 'levelb': {'a': 'hello world'}, 'levelc': True, 'leveld': 2.3, 'levele': [[1,2,3], [1,2]]} filepath='c:/temp/test/dictersave.json'

First save

dt.save(d, filepath=filepath, overwrite=True)

Load

d = dt.load(filepath) ```

Citation

Please cite in your publications if this is useful for your research (see citation).

☕ Support

If you find this project useful, consider supporting me:

Owner

  • Name: Erdogan
  • Login: erdogant
  • Kind: user
  • Location: Den Haag

Machine Learning | Statistics | Bayesian | D3js | Visualizations

Citation (CITATION.cff)

# YAML 1.2
---
authors: 
  -
    family-names: Taskesen
    given-names: Erdogan
    orcid: "https://zenodo.org/badge/latestdoi/584101058"
cff-version: "1.1.0"
date-released: 2023-01-01
keywords: 
  - "python"
  - "dicter"
  - "dictionary"
  - "nested keys"
license: "MIT"
message: "If you use this software, please cite it using these metadata."
repository-code: "https://github.com/erdogant/dicter"
title: "dicter is a Python package with advanced dictionary functions."
version: "0.1.1"
...

GitHub Events

Total
  • Release event: 1
  • Push event: 5
  • Create event: 1
Last Year
  • Release event: 1
  • Push event: 5
  • Create event: 1

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 77
  • Total Committers: 1
  • Avg Commits per committer: 77.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 8
  • Committers: 1
  • Avg Commits per committer: 8.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
erdogant e****t@g****m 77

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 21 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 8
  • Total maintainers: 1
pypi.org: dicter

dicter is a Python package with advanced dictionary functions.

  • Homepage: https://erdogant.github.io/dicter
  • Documentation: https://dicter.readthedocs.io/
  • License: MIT License Copyright (c) 2023 Erdogan Taskesen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 0.1.7
    published 10 months ago
  • Versions: 8
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 21 Last month
Rankings
Dependent packages count: 6.6%
Downloads: 22.2%
Average: 23.6%
Stargazers count: 28.2%
Forks count: 30.5%
Dependent repos count: 30.6%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/codeql-analysis.yml actions
  • actions/checkout v2 composite
  • github/codeql-action/analyze v1 composite
  • github/codeql-action/autobuild v1 composite
  • github/codeql-action/init v1 composite
.github/workflows/pytest.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
requirements-dev.txt pypi
  • irelease * development
  • nbconvert * development
  • numpy * development
  • pytest * development
  • rst2pdf * development
  • sphinx * development
  • sphinx_rtd_theme * development
  • sphinxcontrib-fulltoc * development
  • spyder-kernels ==2.3. development
requirements.txt pypi
  • pandas *
pyproject.toml pypi
  • numpy *
  • pandas *
  • tqdm *