Skip to main content

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'}}}

Metadata

Release files for dict-merger-keep-all 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dict-merger-keep-all 0.10
File Size Uploaded Provenance Actions
dict_merger_keep_all-0.10.tar.gz 5.4 kB Without provenance Details for dict_merger_keep_all-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dict-merger-keep-all 0.10
File Interpreter ABI Platform Actions
dict_merger_keep_all-0.10-py3-none-any.whl Python 3 none any Details for dict_merger_keep_all-0.10-py3-none-any.whl

Total release size: 11.9 kB

Release files / dict_merger_keep_all-0.10.tar.gz

Download URL dict_merger_keep_all-0.10.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e398b2d3a23b51edf39cb880cb513f0f6218407a772d227da968582b5aa8efca
BLAKE2b-256 checksum
How to use checksums
1ab975f7f17095090f6684b9d79dda877db06a48d6513a288e5ad2f88cc5ac39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / dict_merger_keep_all-0.10-py3-none-any.whl

Download URL dict_merger_keep_all-0.10-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2231cea38bd9011bf0b702ddfd0c929f242da6a14fb7aa3709e5cbd8c3f139d5
BLAKE2b-256 checksum
How to use checksums
00ea457b912375276a6917e49557c12b68ca66adc06e32b5164627417c6021d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for dict-merger-keep-all 0.10

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.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page