dict-merger-keep-all


Namedict-merger-keep-all JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/dict_merger_keep_all
SummaryMerges multiple nested dicts without deleting any values (values with same keys are stored in lists)
upload_time2023-01-06 06:03:21
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords merge nested dicts
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Merges multiple nested dicts without deleting any values (values with same keys are stored in lists)



```python

pip install dict-merger-keep-all

```



```python



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





```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/dict_merger_keep_all",
    "name": "dict-merger-keep-all",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "merge,nested dicts",
    "author": "Johannes Fischer",
    "author_email": "<aulasparticularesdealemaosp@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1a/b9/75f7f17095090f6684b9d79dda877db06a48d6513a288e5ad2f88cc5ac39/dict_merger_keep_all-0.10.tar.gz",
    "platform": null,
    "description": "\n# Merges multiple nested dicts without deleting any values (values with same keys are stored in lists)\n\n\n\n```python\n\npip install dict-merger-keep-all\n\n```\n\n\n\n```python\n\n\n\nfrom pprint import pprint as pp\n\nfrom dict_merger_keep_all import dict_merger\n\n\n\npeople = {\n\n    1: {\"name\": \"John\", \"age\": \"27\", \"sex\": \"Male\"},\n\n    2: {\"name\": \"Marie\", \"age\": \"22\", \"sex\": \"Female\"},\n\n    3: {\"name\": \"Luna\", \"age\": \"24\", \"sex\": \"Female\"},\n\n    4: {\n\n        \"name\": \"Peter\",\n\n        \"age\": \"29\",\n\n        \"sex\": [\"Female\", \"Male\"],\n\n        1: \"xx\",\n\n        \"sex2\": (\"Female\", \"Male\"),\n\n    },\n\n}\n\n\n\npeople3 = {\n\n    1: {\"namexxxxxxxxx\": \"John\", \"age\": \"27\", \"sex\": \"Male\"},\n\n    2: {\"name\": \"Marie\", \"age\": \"22\", \"sex\": \"Female\"},\n\n    3: {\"name\": \"Luna\", \"agexxxxxxxxxx\": \"24\", \"sex\": \"Female\"},\n\n    4: {\n\n        \"name\": \"Peter\",\n\n        \"age\": \"29\",\n\n        \"sex\": [\"Female\", \"Male\"],\n\n        1: \"xx\",\n\n        \"sex2\": (\"Female\", \"Male\"),\n\n    },\n\n}\n\npeople2 = {\n\n    11: {\"name\": \"Johnaaa\", \"age\": \"2x337\", \"sex\": \"Maleooo\"},\n\n    21: {\"name\": \"Mariexx\", \"age\": \"22\", \"sex\": \"Female\"},\n\n    13: {\"name\": \"Luna\", \"age\": \"24444\", \"sex\": \"Feoomale\"},\n\n    14: {\n\n        \"name\": \"Peter\",\n\n        \"age\": \"29\",\n\n        \"sex\": [\"Female\", \"Male\"],\n\n        111: \"xx\",\n\n        \"sex2\": (\"Female\", \"Male\"),\n\n    },\n\n}\n\nd1 = {1: {\"a\": \"A\"}, 2: {\"b\": \"B\"}}\n\n\n\nd2 = {2: {\"c\": \"C\"}, 3: {\"d\": [\"D\", \"dd\", \"s\"]}}\n\n\n\ndict1 = {1: {\"a\": 1}, 2: {\"b\": 2}}\n\n\n\ndict2 = {2: {\"c\": 222}, 3: {\"d\": {3, 6}}}\n\n\n\n\n\ndata = {\n\n    \"A\": [1, 2, 3],\n\n    \"B\": [4, 5, 6],\n\n    \"departure\": [\n\n        {\n\n            \"actual\": None,\n\n            \"actual_runway\": None,\n\n            \"airport\": \"Findel\",\n\n            \"delay\": None,\n\n            \"estimated\": \"2020-07-07T06:30:00+00:00\",\n\n            \"estimated_runway\": None,\n\n            \"gate\": None,\n\n            \"iata\": \"LUX\",\n\n            \"icao\": \"ELLX\",\n\n            \"scheduled\": \"2020-07-07T06:30:00+00:00\",\n\n            \"terminal\": None,\n\n            \"timezone\": \"Europe/Luxembourg\",\n\n        },\n\n        {\n\n            \"actual\": None,\n\n            \"actual_runway\": None,\n\n            \"airport\": \"Findel\",\n\n            \"delay\": None,\n\n            \"estimated\": \"2020-07-07T06:30:00+00:00\",\n\n            \"estimated_runway\": None,\n\n            \"gate\": None,\n\n            \"iata\": \"LUX\",\n\n            \"icao\": \"ELLX\",\n\n            \"scheduled\": \"2020-07-07T06:30:00+00:00\",\n\n            \"terminal\": None,\n\n            \"timezone\": \"Europe/Luxembourg\",\n\n        },\n\n        {\n\n            \"actual\": None,\n\n            \"actual_runway\": None,\n\n            \"airport\": \"Findel\",\n\n            \"delay\": None,\n\n            \"estimated\": \"2020-07-07T06:30:00+00:00\",\n\n            \"estimated_runway\": None,\n\n            \"gate\": None,\n\n            \"iata\": \"LUX\",\n\n            \"icao\": \"ELLX\",\n\n            \"scheduled\": \"2020-07-07T06:30:00+00:00\",\n\n            \"terminal\": None,\n\n            \"timezone\": \"Europe/Luxembourg\",\n\n        },\n\n    ],\n\n}\n\n\n\ndata2 = {\"A\": [4, 5, 6]}\n\n\n\nnewdict = dict_merger(people, people2, d1, d2, dict2, dict1, data, data2, people3)\n\npp(newdict)\n\n\n\n\n\n\n\n{1: {'a': ['A', 1],\n\n     'age': ['27', '27'],\n\n     'name': 'John',\n\n     'namexxxxxxxxx': 'John',\n\n     'sex': ['Male', 'Male']},\n\n 2: {'age': ['22', '22'],\n\n     'b': ['B', 2],\n\n     'c': ['C', 222],\n\n     'name': ['Marie', 'Marie'],\n\n     'sex': ['Female', 'Female']},\n\n 3: {'age': '24',\n\n     'agexxxxxxxxxx': '24',\n\n     'd': ['D', 'dd', 's', 3, 6],\n\n     'name': ['Luna', 'Luna'],\n\n     'sex': ['Female', 'Female']},\n\n 4: {1: ['xx', 'xx'],\n\n     'age': ['29', '29'],\n\n     'name': ['Peter', 'Peter'],\n\n     'sex': ['Female', 'Male', 'Female', 'Male'],\n\n     'sex2': ['Female', 'Male', 'Female', 'Male']},\n\n 11: {'age': '2x337', 'name': 'Johnaaa', 'sex': 'Maleooo'},\n\n 13: {'age': '24444', 'name': 'Luna', 'sex': 'Feoomale'},\n\n 14: {111: 'xx',\n\n      'age': '29',\n\n      'name': 'Peter',\n\n      'sex': ['Female', 'Male'],\n\n      'sex2': ['Female', 'Male']},\n\n 21: {'age': '22', 'name': 'Mariexx', 'sex': 'Female'},\n\n 'A': [1, 2, 3, 4, 5, 6],\n\n 'B': [4, 5, 6],\n\n 'departure': {0: {'actual': None,\n\n                   'actual_runway': None,\n\n                   'airport': 'Findel',\n\n                   'delay': None,\n\n                   'estimated': '2020-07-07T06:30:00+00:00',\n\n                   'estimated_runway': None,\n\n                   'gate': None,\n\n                   'iata': 'LUX',\n\n                   'icao': 'ELLX',\n\n                   'scheduled': '2020-07-07T06:30:00+00:00',\n\n                   'terminal': None,\n\n                   'timezone': 'Europe/Luxembourg'},\n\n               1: {'actual': None,\n\n                   'actual_runway': None,\n\n                   'airport': 'Findel',\n\n                   'delay': None,\n\n                   'estimated': '2020-07-07T06:30:00+00:00',\n\n                   'estimated_runway': None,\n\n                   'gate': None,\n\n                   'iata': 'LUX',\n\n                   'icao': 'ELLX',\n\n                   'scheduled': '2020-07-07T06:30:00+00:00',\n\n                   'terminal': None,\n\n                   'timezone': 'Europe/Luxembourg'},\n\n               2: {'actual': None,\n\n                   'actual_runway': None,\n\n                   'airport': 'Findel',\n\n                   'delay': None,\n\n                   'estimated': '2020-07-07T06:30:00+00:00',\n\n                   'estimated_runway': None,\n\n                   'gate': None,\n\n                   'iata': 'LUX',\n\n                   'icao': 'ELLX',\n\n                   'scheduled': '2020-07-07T06:30:00+00:00',\n\n                   'terminal': None,\n\n                   'timezone': 'Europe/Luxembourg'}}}\n\n\n\n\n\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Merges multiple nested dicts without deleting any values (values with same keys are stored in lists)",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/dict_merger_keep_all"
    },
    "split_keywords": [
        "merge",
        "nested dicts"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "00ea457b912375276a6917e49557c12b68ca66adc06e32b5164627417c6021d1",
                "md5": "1d7b6ff1e39b91b31dc69edc664250c2",
                "sha256": "2231cea38bd9011bf0b702ddfd0c929f242da6a14fb7aa3709e5cbd8c3f139d5"
            },
            "downloads": -1,
            "filename": "dict_merger_keep_all-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1d7b6ff1e39b91b31dc69edc664250c2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6494,
            "upload_time": "2023-01-06T06:03:19",
            "upload_time_iso_8601": "2023-01-06T06:03:19.509133Z",
            "url": "https://files.pythonhosted.org/packages/00/ea/457b912375276a6917e49557c12b68ca66adc06e32b5164627417c6021d1/dict_merger_keep_all-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1ab975f7f17095090f6684b9d79dda877db06a48d6513a288e5ad2f88cc5ac39",
                "md5": "eea9a1d5f7995a87931e79495a9a3747",
                "sha256": "e398b2d3a23b51edf39cb880cb513f0f6218407a772d227da968582b5aa8efca"
            },
            "downloads": -1,
            "filename": "dict_merger_keep_all-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "eea9a1d5f7995a87931e79495a9a3747",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5441,
            "upload_time": "2023-01-06T06:03:21",
            "upload_time_iso_8601": "2023-01-06T06:03:21.824077Z",
            "url": "https://files.pythonhosted.org/packages/1a/b9/75f7f17095090f6684b9d79dda877db06a48d6513a288e5ad2f88cc5ac39/dict_merger_keep_all-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-06 06:03:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "dict_merger_keep_all",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "dict-merger-keep-all"
}
        
Elapsed time: 0.50951s