Merges multiple nested dicts without deleting any values (values with same keys are stored in lists)
Project description
Merges multiple nested dicts without deleting any values (values with same keys are stored in lists)
pip install dict-merger-keep-all
from pprint import pprint as pp
from dict_merger_keep_all import dict_merger
people = {
1: {"name": "John", "age": "27", "sex": "Male"},
2: {"name": "Marie", "age": "22", "sex": "Female"},
3: {"name": "Luna", "age": "24", "sex": "Female"},
4: {
"name": "Peter",
"age": "29",
"sex": ["Female", "Male"],
1: "xx",
"sex2": ("Female", "Male"),
},
}
people3 = {
1: {"namexxxxxxxxx": "John", "age": "27", "sex": "Male"},
2: {"name": "Marie", "age": "22", "sex": "Female"},
3: {"name": "Luna", "agexxxxxxxxxx": "24", "sex": "Female"},
4: {
"name": "Peter",
"age": "29",
"sex": ["Female", "Male"],
1: "xx",
"sex2": ("Female", "Male"),
},
}
people2 = {
11: {"name": "Johnaaa", "age": "2x337", "sex": "Maleooo"},
21: {"name": "Mariexx", "age": "22", "sex": "Female"},
13: {"name": "Luna", "age": "24444", "sex": "Feoomale"},
14: {
"name": "Peter",
"age": "29",
"sex": ["Female", "Male"],
111: "xx",
"sex2": ("Female", "Male"),
},
}
d1 = {1: {"a": "A"}, 2: {"b": "B"}}
d2 = {2: {"c": "C"}, 3: {"d": ["D", "dd", "s"]}}
dict1 = {1: {"a": 1}, 2: {"b": 2}}
dict2 = {2: {"c": 222}, 3: {"d": {3, 6}}}
data = {
"A": [1, 2, 3],
"B": [4, 5, 6],
"departure": [
{
"actual": None,
"actual_runway": None,
"airport": "Findel",
"delay": None,
"estimated": "2020-07-07T06:30:00+00:00",
"estimated_runway": None,
"gate": None,
"iata": "LUX",
"icao": "ELLX",
"scheduled": "2020-07-07T06:30:00+00:00",
"terminal": None,
"timezone": "Europe/Luxembourg",
},
{
"actual": None,
"actual_runway": None,
"airport": "Findel",
"delay": None,
"estimated": "2020-07-07T06:30:00+00:00",
"estimated_runway": None,
"gate": None,
"iata": "LUX",
"icao": "ELLX",
"scheduled": "2020-07-07T06:30:00+00:00",
"terminal": None,
"timezone": "Europe/Luxembourg",
},
{
"actual": None,
"actual_runway": None,
"airport": "Findel",
"delay": None,
"estimated": "2020-07-07T06:30:00+00:00",
"estimated_runway": None,
"gate": None,
"iata": "LUX",
"icao": "ELLX",
"scheduled": "2020-07-07T06:30:00+00:00",
"terminal": None,
"timezone": "Europe/Luxembourg",
},
],
}
data2 = {"A": [4, 5, 6]}
newdict = dict_merger(people, people2, d1, d2, dict2, dict1, data, data2, people3)
pp(newdict)
{1: {'a': ['A', 1],
'age': ['27', '27'],
'name': 'John',
'namexxxxxxxxx': 'John',
'sex': ['Male', 'Male']},
2: {'age': ['22', '22'],
'b': ['B', 2],
'c': ['C', 222],
'name': ['Marie', 'Marie'],
'sex': ['Female', 'Female']},
3: {'age': '24',
'agexxxxxxxxxx': '24',
'd': ['D', 'dd', 's', 3, 6],
'name': ['Luna', 'Luna'],
'sex': ['Female', 'Female']},
4: {1: ['xx', 'xx'],
'age': ['29', '29'],
'name': ['Peter', 'Peter'],
'sex': ['Female', 'Male', 'Female', 'Male'],
'sex2': ['Female', 'Male', 'Female', 'Male']},
11: {'age': '2x337', 'name': 'Johnaaa', 'sex': 'Maleooo'},
13: {'age': '24444', 'name': 'Luna', 'sex': 'Feoomale'},
14: {111: 'xx',
'age': '29',
'name': 'Peter',
'sex': ['Female', 'Male'],
'sex2': ['Female', 'Male']},
21: {'age': '22', 'name': 'Mariexx', 'sex': 'Female'},
'A': [1, 2, 3, 4, 5, 6],
'B': [4, 5, 6],
'departure': {0: {'actual': None,
'actual_runway': None,
'airport': 'Findel',
'delay': None,
'estimated': '2020-07-07T06:30:00+00:00',
'estimated_runway': None,
'gate': None,
'iata': 'LUX',
'icao': 'ELLX',
'scheduled': '2020-07-07T06:30:00+00:00',
'terminal': None,
'timezone': 'Europe/Luxembourg'},
1: {'actual': None,
'actual_runway': None,
'airport': 'Findel',
'delay': None,
'estimated': '2020-07-07T06:30:00+00:00',
'estimated_runway': None,
'gate': None,
'iata': 'LUX',
'icao': 'ELLX',
'scheduled': '2020-07-07T06:30:00+00:00',
'terminal': None,
'timezone': 'Europe/Luxembourg'},
2: {'actual': None,
'actual_runway': None,
'airport': 'Findel',
'delay': None,
'estimated': '2020-07-07T06:30:00+00:00',
'estimated_runway': None,
'gate': None,
'iata': 'LUX',
'icao': 'ELLX',
'scheduled': '2020-07-07T06:30:00+00:00',
'terminal': None,
'timezone': 'Europe/Luxembourg'}}}
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
File details
Details for the file dict_merger_keep_all-0.10.tar.gz
.
File metadata
- Download URL: dict_merger_keep_all-0.10.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e398b2d3a23b51edf39cb880cb513f0f6218407a772d227da968582b5aa8efca |
|
MD5 | eea9a1d5f7995a87931e79495a9a3747 |
|
BLAKE2b-256 | 1ab975f7f17095090f6684b9d79dda877db06a48d6513a288e5ad2f88cc5ac39 |
File details
Details for the file dict_merger_keep_all-0.10-py3-none-any.whl
.
File metadata
- Download URL: dict_merger_keep_all-0.10-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2231cea38bd9011bf0b702ddfd0c929f242da6a14fb7aa3709e5cbd8c3f139d5 |
|
MD5 | 1d7b6ff1e39b91b31dc69edc664250c2 |
|
BLAKE2b-256 | 00ea457b912375276a6917e49557c12b68ca66adc06e32b5164627417c6021d1 |