0
x = { "123456" : {2017-04-16': {'2298': 'yes','578' : 'no'}} }
y = { "123456" : {2017-04-16': {'38': 'yes'}}}
expected_output = {"123456" : {'2017-04-16': {'2298': 'yes','38' :'yes','578' : 'no'}}}

How to do above operation efficiently??
I have to perform 100M+ such operation for 1000's of feilds

I tried navigating into dictionary and combining them, but it takes time which is not acceptable

  • Maybe this can be useful to you: https://stackoverflow.com/questions/38987/how-do-i-merge-two-dictionaries-in-a-single-expression-in-python-taking-union-o – SGali Jul 14 '20 at 13:21

1 Answers1

0

You can use the following code to merge the dictionaries together:

For Python versions 3.5 or newer, you can execute:

x = { "123456" : {'2017-04-16': {'2298': 'yes','578' : 'no'}} }
y = { "123456" : {'2017-04-16': {'38': 'yes'}}}

newDict = {**x, **y}

For Python versions 3.9 or newer, you can also execute:

newDict = x | y

instead of newDict = {**x, **y}

Gavin Wong
  • 1,254
  • 1
  • 6
  • 15
  • new Dict will be newDict = {'123456': {'2017-04-16': {'38': 'yes'}}} I need expected_output = {"123456" : {'2017-04-16': {'2298': 'yes','38' :'yes','578' : 'no'}}} – Chinmay Hebbal Jul 14 '20 at 13:34