A package for operating
Project description
FastOptDict Document
0x00 Introduction
FastOptDict is a simple dictionary library. It allows you to find all the keys, values, and paths in the dictionary variable.
For example, we have a dictionary variable and we have to find out the value for the key "test".
>>> import FastOptDict
>>> dict_data = {"a": "b", "c": "d", "e": [{"f": "a"}, "e", {"h": ["tt", "dd"]}], "h": ["tt", "dd"], "i": "c","z": {"f": "a","t":{"x":"z"}}}
>>> value_list = FastOptDict.get_value_by_key("a")
>>> print(value_list)
It uses a path generation algorithm to finish the task instead of using regex.
0x01 Install
pip install FastOptDict
0x02 Usage
-
Find all values from the dictionary variable, and return all the values by the key.
dict_data = {"a": "b", "c": "d", "e": [{"f": "a"}, "e", {"h": ["tt", "dd"]}], "h": ["tt", "dd"], "i": "c","z": {"f": "a","t":{"x":"z"}}} value_list = FastOptDict.get_value_by_key("a") print(value_list) [['tt', 'dd'], ['tt', 'dd']]
-
Find all keys from the dictionary variable, and return all the values of the keys equal to what you input. You can also convert the result into an easy way to read.
value_list = FastOptDict.get_value_by_key("a") print(value_list) ['/z/f', '/e/setoptlist(0)/f'] value_list = FastOptDict.get_value_by_key("a",convert=True) print(value_list) ["dict['e'][0]['f']", "dict['z']['f']"] value_list = get_key_by_value(dict_data, [{"f": "a"}, "e", {"h": ["tt", "dd"]}], convert=True) print(value_list) ["dict['e']"]
-
Find all keys and values from the dictionary variable, Even though what you input is a dictionary variable.
value_list = FastOptDict.get_all_by_key(dict_data,"f") print(value_list) value_list = FastOptDict.get_all_by_key(dict_data, "f",convert=True) print(value_list) [{'path': '/z/f', 'value': 'a'}, {'path': '/e/setoptlist(0)/f', 'value': 'a'}] [{'path': "dict['z']['f']", 'value': 'a'}, {'path': "dict['e'][0]['f']", 'value': 'a'}] value_list = FastOptDict.get_all_by_key(dict_data, "e",convert=True) print(value_list) [{'path': "dict['e']", 'value': [{'f': 'a'}, 'e', {'h': ['tt', 'dd']}]}]
-
Find paths from the dictionary variable by key. For example, the dictionary variable is {"a":{"b":"c","d":"e"}}, the path of key "b" is dict["a"], and we can use dict["a"]["d"] to get the value finally.
value_list = FastOptDict.get_path_by_key(dict_data, "f") print(value_list) value_list = FastOptDict.get_path_by_key(dict_data, "f",convert=True) print(value_list) ['/z/f', '/e/setoptlist(0)/f'] ["dict['e'][0]['f']", "dict['z']['f']"]
-
Find paths from the dictionary variable by values.
value_list = get_path_by_value(dict_data,[{"f": "a"}, "e", {"h": ["tt", "dd"]}]) print(value_list) value_list = get_path_by_value(dict_data, [{"f": "a"}, "e", {"h": ["tt", "dd"]}],convert=True) print(value_list) ['/e/setoptlist(2)', '/', '/e/setoptlist(0)'] ["dict['']", "dict['e'][0]", "dict['e'][2]"]
-
Find keyword from keynames and values
print(search_all_by_str(dict_data,"dd")) print(search_all_by_str(dict_data, "dd",True)) ['/h/setoptlist(1)', '/h', '/e/setoptlist(2)/h', '/e/setoptlist(2)/h/setoptlist(1)'] ["dict['h']", "dict['e'][2]['h'][1]", "dict['e'][2]['h']", "dict['h'][1]"]
-
Find keyword in keynames
print(search_key_in_value(dict_data, ["tt", "dd"],convert=True)) ["dict['e'][2]['h']", "dict['h']"]
-
Get value from path
print(get_value_by_path(dict_data,"/e")) [{'f': 'a'}, 'e', {'h': ['tt', 'dd']}]
0x03 MIT License
Copyright (c) 2022 JulianZackWu
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file FastOptDict-1.0.0.tar.gz.
File metadata
- Download URL: FastOptDict-1.0.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43646c8406c5805e3c34b136ae3d70a97169c135accb6f41f28e0ad83db9532d
|
|
| MD5 |
aeee600ba89de38403f9aacc652c4084
|
|
| BLAKE2b-256 |
b5530d5632f7dee7f6562c6fd04256dfc05911be18a6a9c31dc19420f2a9ac67
|
File details
Details for the file FastOptDict-1.0.0-py3-none-any.whl.
File metadata
- Download URL: FastOptDict-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63c9b9c34f5c5f274944f95d645422db2b3b05edd054fbfe83c16d3b09e5bc39
|
|
| MD5 |
3eb13b4778520e4fd981b94fd071951d
|
|
| BLAKE2b-256 |
e8db8004dc14bbaa6a6b3d8324144217977d015df11061747c831bc5445e1e34
|