Python Forum
Merge dicts without override
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Merge dicts without override
#1
Just as an FYI I'm still new to working with dicts so the way I have these structured could probably be improved. Basically I have 3 dicts with different information pertaining to individuals contained in each. Each individual has an ID and that is used as the keys. I've tried multiple ways of combining them but each method results in the data being overridden. Also, some ID keys may not be in all of the dicts.

Below are examples of each dict. If anyone has a way of accomplishing this task and/or advice on how to improve the structures I would appreciate it.

#alias dict
{
    "10084": {
        "aliases": {
            "first_last": "Loren Meyer",
            "last_first": "Meyer, Loren"
        }
    },
    "10111": {
        "aliases": {
            "first_last": "Cory Higgins",
            "last_first": "Higgins, Cory"
        }
    },
    "10163": {
        "aliases": {
            "first_last": "Antoine Wright",
            "last_first": "Wright, Antoine"
        }
    }
}

#vitals dict
{
    "10084": {
        "vitals": {
            "ht": 82,
            "wt": 257,
            "birth_date": "12/30/1972"
        }
    },
    "10111": {
        "vitals": {
            "ht": 77,
            "wt": 180,
            "birth_date": "6/14/1989"
        }
    },
    "10163": {
        "vitals": {
            "ht": 79,
            "wt": 210,
            "birth_date": "2/6/1984"
        }
    }
}

#combine dict
{
    "10084": {
        "combine": {
            "span": 81.0,
            "reach": 100.0,
            "body_fat": 4.1,
        }
    },
    "10111": {
        "combine": {
            "span": 81.0,
            "reach": 100.0,
            "body_fat": 9.1,
        }
    },
    "10163": {
        "combine": {
            "span": 75.0,
            "reach": 85.0,
            "body_fat": 6.1,
        }
    }
}
Reply


Messages In This Thread
Merge dicts without override - by chisox721 - Jul-19-2019, 01:16 AM
RE: Merge dicts without override - by ichabod801 - Jul-19-2019, 01:38 AM
RE: Merge dicts without override - by perfringo - Jul-19-2019, 08:01 AM
RE: Merge dicts without override - by DeaD_EyE - Jul-19-2019, 04:03 PM
RE: Merge dicts without override - by chisox721 - Jul-20-2019, 01:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python update binary object (override delivered Object properties) pierre38 4 1,801 May-19-2022, 07:52 AM
Last Post: pierre38
  dict class override: how access parent values? Andrey 1 1,669 Mar-06-2022, 10:49 PM
Last Post: deanhystad
  Due to MDLable ID does not have get attribute how to override on this jayyu 0 2,853 Dec-20-2021, 10:38 AM
Last Post: jayyu
  Override a library function that is not in __all__ Weird 7 3,324 Aug-23-2021, 05:03 PM
Last Post: Larz60+
Star Recursively convert nested dicts to dict subclass Alfalfa 1 2,919 Jan-22-2021, 05:43 AM
Last Post: buran
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,423 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Still working with dicts menator01 2 2,040 Nov-07-2019, 07:15 AM
Last Post: perfringo
  convert List of Dicts into a 2 deep Nested Dict rethink 1 3,239 Aug-23-2019, 05:28 PM
Last Post: ichabod801
  Could I override a fully implemented method zatlas1 2 2,427 Jun-06-2019, 02:20 AM
Last Post: zatlas1
  How can we override decorator? bhojendra 2 9,414 May-12-2019, 11:15 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020