get_set_nested_dict
Get or Set a nested value of nested dict by path
def get_set_nested_dict(nested_dict, path, **kwargs):
"""
Get or Set a nested value of nested dict by path
:param nested_dict: nested dict object
{
"club": [
{
"manager": {
"last_name": "Lionel",
"first_name": "Messi"
}
}
]
}
:param path: path to access the nested dict value
"club[0].manager.first_name"
:param kwargs: {setter_value: value}
setter_value='Pulga'
:return: <modified_nested_dict>, getter_value
({'club': [{'manager': {'last_name': 'Pulga', 'first_name': 'Messi'}}]}, 'Lionel')
"""
#####Installation: https://pypi.org/project/get_set_nested_dict/
pip install get_set_nested_dict
#####Usage:
nested_dict = {
"key": [
{
"sub_key": {
"sub_sub_key_1": "Value_1",
"sub_sub_key_2": "Value_2"
}
}
]
}
before:
sub_sub_value_1 = nested_dict['key'][0]['sub_key']['sub_sub_key_1']
after:
from get_set_nested_dict import get_set_nested_dict
nested_dict, sub_sub_value_1 = get_set_nested_dict(nested_dict, "key[0].sub_key.sub_sub_key_1")
#####Example:
nested_dict = {
"club": [
{
"manager": {
"last_name": "Lionel",
"first_name": "Messi"
}
}
]
}
before:
manager_last_name = nested_dict['club'][0]['manager']['last_name']
nested_dict['club'][0]['manager']['last_name'] = 'Pulga'
after:
from get_set_nested_dict import get_set_nested_dict
path = "club[0].manager.last_name"
nested_dict, manager_last_name = get_set_nested_dict(nested_dict, path, setter_value='Pulga')
>>> nested_dict
{'club': [{'manager': {'last_name': 'Pulga', 'first_name': 'Messi'}}]}
>>> manager_last_name
'Lionel'
Release files for get-set-nested-dict 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| get_set_nested_dict-0.1.1.tar.gz | 2.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| get_set_nested_dict-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.7 kB
Release files / get_set_nested_dict-0.1.1.tar.gz
| Download URL | get_set_nested_dict-0.1.1.tar.gz |
|---|---|
| Size | 2.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b9bed98d677effde52f56e0db135e3518c59f8d88fa870304ea3ca73e2d80838
|
|
BLAKE2b-256 checksum How to use checksums |
23b8952565e31311756f4a0d1e21f5c4423eb07cc6e75e847c79200c481c1acd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9
|
Release files / get_set_nested_dict-0.1.1-py3-none-any.whl
| Download URL | get_set_nested_dict-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b61fef6a6a3746f9de3a9a0babf0f150bced0f32ed8664e83931fd3b4dfe8c38
|
|
BLAKE2b-256 checksum How to use checksums |
3aa0ac0222e6e4a28e9d2a4b1461aa16fed1546604dd43bdd0be213ede88a4fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.9
|