A Python `dict` with a merge() method.
Project description
mergedict - A Python dict with a merge() method
A MergeDict is a dict with a merge() method. merge() is like dict.update()…
from mergedict import MergeDict d1 = MergeDict({'a': 1, 'b': 'one'}) d1.merge({'a':2, 'c': [2]}) assert d1 == {'a': 2, 'c': [2], 'b': 'one'}
A MergeDict can be subclassed to create custom “merge” operations based on the type of an item value.
from mergedict import MergeDict class SumDict(MergeDict): @MergeDict.dispatch(int) def merge_int(this, other): return this + other d2 = SumDict({'a': 1, 'b': 'one'}) d2.merge({'a':2, 'b': 'two'}) assert d2 == {'a': 3, 'b': 'two'}
mergedict module comes with a ConfigDict that will extend/update lists/sets/dicts.
from mergedict import ConfigDict d3 = ConfigDict({'a': 1, 'my_list': [1, 2]}) d3.merge({'a':2, 'my_list': [3, 4]}) assert d3 == {'a': 2, 'my_list': [1, 2, 3, 4]}
Project Details
Project management on github - https://github.com/schettino72/mergedict/
license
The MIT License Copyright (c) 2013 Eduardo Naufel Schettino
see LICENSE file
developers / contributors
Eduardo Naufel Schettino — main author
Sebastian Pipping — build system fixes
install
$ pip install mergedict
or download and:
$ python setup.py install
tests
To run the tests:
$ py.test
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
Built Distributions
File details
Details for the file mergedict-0.3.0.tar.gz
.
File metadata
- Download URL: mergedict-0.3.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ec9223695ac469aecac363add1901f2988e0ae3911403502a3eb700d71104bf |
|
MD5 | 22b9e7bf6b7275f7f6697f009e742901 |
|
BLAKE2b-256 | c66bb2d6be3b47d91da004fc92a12c6fec1986585d41d7961c7c073e1cb3901b |
File details
Details for the file mergedict-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: mergedict-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4999d3e8f543fa55753179ca408ae9247f504729395d015401e954572599d0b8 |
|
MD5 | a27b17b2b70435750707215371ee75b6 |
|
BLAKE2b-256 | f9dac80282d35e1d64c36e51962756a52867f23637591e0d9e0a1fd80de123fe |
File details
Details for the file mergedict-0.3.0-py2-none-any.whl
.
File metadata
- Download URL: mergedict-0.3.0-py2-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5a519b683b9ef00f807b308628d11186d1ee3cdf95e73e57cd225f8c57a6cdb |
|
MD5 | 894e0e4b7ed8b50a7033caf672524090 |
|
BLAKE2b-256 | 955d79f688002fac45eda3d1965d1a099d5cbd093d45f4df0cb236eb8634b4af |