Cython recursive dictionary merging
Project description
Dict merger
Simple Cython+Python library for merge python dictionaries recursively
Usage
from dict_merger.static_merger import merge
a = {1: 2, 2: 3, 3: {1: 1, 2: 3}, 4: 1}
b = {1: 5, 3: {1: 2}, 5: 3}
print(merge(a, b))
# {1: 5, 2: 3, 3: {1: 2, 2: 3}, 4: 1, 5: 3}
API
# dict_merger.static_merger - pure Cython module with static python types
# dict_merger.dynamic_merger - same module, but with dynamic types, works a bit slower
def merge(first_dict: dict, second_dict: dict) -> dict:
"""
Merge 2 dicts recursively. If more than one given map or object defines the same key or attribute,
then the one that is later in the argument sequence takes precedence.
:param first_dict:
:param second_dict:
:return:
"""
...
def merge_inplace(first_dict: dict, second_dict: dict) -> None:
"""
Merge 2 dicts recursively. If more than one given map or object defines the same key or attribute,
then the one that is later in the argument sequence takes precedence.
First dict will contain merged version
"""
...
def merge_many(dicts: List[dict]) -> dict:
"""
Merge list of dicts. If more than one given map or object defines the same key or attribute,
then the one that is later in the argument sequence takes precedence.
:param dicts: list of dicts
:return: dict
"""
...
Installation
# via pypi
pip install dict_merger
# via git
pip install git+https://github.com/TeaDove/dict_merger.git #@branch/tag
# build locally
git clone https://github.com/TeaDove/dict_merger.git #@branch/tag
cd dict_merger
make install
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dict_merger-0.0.2.1.tar.gz
(99.4 kB
view hashes)
Built Distribution
Close
Hashes for dict_merger-0.0.2.1-cp38-cp38-macosx_10_14_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7e95df87ec5eeb4f5a8532bfce470b05459ac3d918cab2c7a93b52220293d7b |
|
MD5 | e228b6d03b2d6dc74d995df1b339b811 |
|
BLAKE2b-256 | 398a64f456a9b7497962e6146a5dbfa6565a72889e6f439954faa3716d3dc909 |