Python Dictionary Utility Package
This package contains a collection of functions that perform various operations on Python dictionaries.
Features
concat_dict(dict1, dict2):
Takes two dictionaries as input and returns a new dictionary that is the result of merging the keys and values of both input dictionaries.
key_exists(dictionary, key):
Takes a dictionary and a key as input and returns a Boolean indicating whether the key exists in the dictionary.
value_exists(dictionary, value):
Takes a dictionary and a value as input and returns a Boolean indicating whether the value exists in the dictionary.
clone(obj):
Takes an object as input and returns a deep copy of the object.
is_empty(dictionary):
Takes a dictionary as input and returns a Boolean indicating whether the dictionary is empty.
get_value_from_dict(dictionary, key_path): Takes a dictionary and a key path as input and returns the value associated with the key path.
is_subset(dict1, dict2):
Takes two dictionaries as input and returns a Boolean indicating whether dict1 is a subset of dict2.
sort_dict_by_key(d):
Takes a dictionary as input and returns a new dictionary with the items sorted by key.
sort_dict_by_custom_key(d, key_extractor):
Takes a dictionary and a key extractor function as input and returns a new dictionary with the items sorted by the custom key extractor.
pretty_print_dict(d, indent):
Takes a dictionary and an indentation level as input and pretty prints the dictionary.
iterate_dict(d):
Takes a dictionary as input and returns an iterator over the key-value pairs of the dictionary.
clone_async(obj):
Takes an object as input and returns a deep copy of the object asynchronously.
Installation
To install the package, run the following command:
pip install pydicttool
Usage
from python_dictionary_utility import *
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
# Concatenate two dictionaries
result = concat_dict(dict1, dict2)
print(result) # {'a': 1, 'b': 2, 'c': 3, 'd': 4}
# Check if key exists in dictionary
result = key_exists(dict1, 'a')
print(result) # True
# Check if value exists in dictionary
result = value_exists(dict1, 2)
print(result) # True
# Clone object
result = clone({'a': [1, 2, 3]})
print(result) # {'a': [1, 2, 3]}
# Check if dictionary is empty
result = is_empty({})
print(result) # True
# Get value from dictionary by key path
result = get_value_from_dict({'a': {'b': {'c': 1}}}, 'a.b.c')
print(result) # 1
# Check if one dictionary is subset of another
original_dict = {'c': 3, 'a': 1, 'b': 2}
sorted_dict = sort_dict_by_key(original_dict)
print(sorted_dict) # {'a': 1, 'b': 2, 'c': 3}
original_dict = {'c': 3, 'a': 1, 'b': 2}
# Custom key extractor function
def custom_key_extractor(key, value):
return value
sorted_dict = sort_dict_by_custom_key(original_dict, custom_key_extractor)
print(sorted_dict) # {'a': 1, 'b': 2, 'c': 3}
original_dict = {'c': 3, 'a': 1, 'b': 2}
pretty_print_dict(original_dict, 2)
# Output:
# {
# "a": 1,
# "b": 2,
# "c": 3
# }
original_dict = {'c': 3, 'a': 1, 'b': 2}
for key, value in iterate_dict(original_dict):
print(f'{key}: {value}')
# Output:
# c: 3
# a: 1
# b: 2
``
# Clone object
result = clone({'a': [1, 2, 3]})
print(result) # {'a': [1, 2, 3]}
clone_async example usage for python 3.8>=
import asyncio
# Original object
original_obj = {'a': [1, 2, 3], 'b': {'c': 4, 'd': 5}}
async def main():
# Asynchronously clone the object
cloned_obj = await clone_async(original_obj)
# Print the cloned object
print(cloned_obj) # {'a': [1, 2, 3], 'b': {'c': 4, 'd': 5}}
# Run the main function
await main()
clone_async example usage for python 3.7<
import asyncio
# Original object
original_obj = {'a': [1, 2, 3], 'b': {'c': 4, 'd': 5}}
async def main():
# Asynchronously clone the object
cloned_obj = await clone_async(original_obj)
# Print the cloned object
print(cloned_obj) # {'a': [1, 2, 3], 'b': {'c': 4, 'd': 5}}
# Run the main function
asyncio.run(main())
Metadata
Release files for pydicttools 0.1.0
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 | |
|---|---|---|---|---|
| pydicttools-0.1.0.tar.gz | 4.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydicttools-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.4 kB
Release files / pydicttools-0.1.0.tar.gz
| Download URL | pydicttools-0.1.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc23c1d21d2cb949fb46a334f65a3ec5cebf8185a736b7fd0b28a44cfed5e2b8
|
|
BLAKE2b-256 checksum How to use checksums |
76ab197b73ba64500f65b736f346455d87eaa3be8025371e84e48177915eff32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.6 Linux/5.10.16.3-microsoft-standard-WSL2
|
Release files / pydicttools-0.1.0-py3-none-any.whl
| Download URL | pydicttools-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f214e53604d430f1e4450cef6924445211aa63629b541bc2a5e0cd35a0dc4487
|
|
BLAKE2b-256 checksum How to use checksums |
5918ba02e779e2b4384bb0cc7d0e789579075831ef74c0dbeec5c7f2b4157110
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.6 Linux/5.10.16.3-microsoft-standard-WSL2
|
Security for pydicttools 0.1.0
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.