Linked Dictionary
Advanced python dictionary(hash-table), which can link it-self keys and make calculations into the keys of the dict
Installation
Use the package manager pip to install foobar.
pip install linked-dict
Usage
The syntax of expressions:
{'key' : '...$(expression)$...'}
Initialization:
from linked_dict import LinkedDict
from json import dumps
dictionary = LinkedDict({}) # {} - your dict
Examples:
Simple link:
example = LinkedDict(
{
'a': 5,
'b': '$(a)$'
}
)
print(dumps(example))
{
'a': 5,
'b': 5
}
Expression with one key. As you can see now I added a space outside this expression, and the final value is string:
example = LinkedDict(
{
'a': 5,
'b': '$(a * 2)$ ' # here with a space
}
)
print(dumps(example))
{
'a': 5,
'b': '10 '
}
Link other expressions:
example = LinkedDict(
{
'a': 5,
'b': 100,
'c': '$(b + d)$',
'd': '$(b + a)$'
}
)
print(dumps(example))
{
'a': 5,
'b': 100,
'c': 205,
'd': 105
}
Using all built-in types:
example = LinkedDict(
{
'a': ['one_item'],
'b': '$(a + ["another_item"])$'
}
)
print(dumps(example))
{
'a': ['one_item'],
'b': ['one_item', 'another_item']
}
Using your own functions into expressions:
some_func = lambda arg: arg + 1
example = LinkedDict(
{
'a': 5,
'b': '$(some_func(a))$'
},
loc=locals(), # to be able to use your functions
glob=globals() # to be able to use your functions
)
print(dumps(example))
{
'a': 5,
'b': 5
}
Changing:
When you change a value, all values that link it change their values too. But links work only in one direction
example = LinkedDict(
{
'a': 5,
'b': '$(a)$'
}
)
print(example)
# >>> {'a': 5, 'b': 5}
example['a'] = 'another_val'
print(example)
# >>> {'a': 'another_val', 'b': 'another_val'}
example['b'] = '4'
print(example)
# >>> {'a': 'another_val', 'b': 4}
# !!! 'b' links 'a', but 'a' doesn't link 'b'
Warning:
1. Keys of your dict must be only strings
{5: 'abc', True: []} # is prohibited
{'5': 'abc', 'True': []} # is allowed
2. Don't make loops of links. Dictionary is protected of this, but you will get the Error
Contributing:
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Metadata
Release files for linked-dict 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| linked-dict-0.0.2.tar.gz | 5.4 kB | Without provenance | Details for linked-dict-0.0.2.tar.gz |
Release files / linked-dict-0.0.2.tar.gz
| Download URL | linked-dict-0.0.2.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
655785e2d9f4ca3d014aed7dd81ead868a5567e880d2daf391b803d9bcca834e
|
|
BLAKE2b-256 checksum How to use checksums |
f049f338bb533db7dfca716d72ca3749d890455b4235a3b2de4af9c99e0ad3a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Security for linked-dict 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.