Small dictionary search utils
Project description
Dictionary Search tools
In a nutshell Dictionary Search
is a small library to search in a dictionaries recursively.
Also have some other dictionary tools to make your life easier.
Install
> pip install dictionary-search
Search
# File: example.py
from dictionary_search import search_first, search_all
d = {
"a": {
"b": {
"c": "C value 1"
}
},
"e": "f",
"h": [
{
"i": "j"
},
{
"c": "C value 2"
}
]
}
print("Search First: ", search_first(d, "c"))
print("Search All: ", search_all(d, "c"))
print()
print("Search First (path as tuple): ", search_first(d, "c", path_as_string=False))
print("Search All (path as tuple): ", search_all(d, "c", path_as_string=False))
After running the code, you will see:
> python examples/example.py
Search First: ('a.b.c', 'C value 1')
Search All: [('a.b.c', 'C value 1'), ('h.c', 'C value 2')]
Search First (path as tuple): (('a', 'b', 'c'), 'C value 1')
Search All (path as tuple): [(('a', 'b', 'c'), 'C value 1'), (('h', 'c'), 'C value 2')]
Flat and Nest
Allow you to flat and rebuild a dict. Nest only work with str and index keys.
data = {"a": {"b": 1, "c": 2}}
flat_data = flat(data) # will produce: [("a.b", 1), ("a.c", 2)]
assert data == nest(flat_data)
TODO: describe list
If you want more information, please take a look to our test
Authors
License
Dictionary Search is Open Source and available under the MIT.
Contributions
Contributions are very welcome. See CONTRIBUTING.md or skim existing tickets to see where you could help out.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file dictionary-search-1.1.1.tar.gz
.
File metadata
- Download URL: dictionary-search-1.1.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61651e7c9d9826f58cc904a384db7a4fac4f862f6ee378643fb343adfae94443 |
|
MD5 | 3f4876b96c4060420b13a7aa541599e2 |
|
BLAKE2b-256 | db35a6d0d497d655621fe10acd2a0d863a7a4a80f2493f9f85135357f92553d9 |