2

suppose I have this:

config = {
    "a": {
        "hello": 1,
        "goodbye": 2,
    }
}

and I want to update ["a"]["hello"] to 10 like this:

update = {
    "a": {
        "hello": 10
    }
}

config.update(update)

at this point config is now:

config = {
    "a": {
        "hello": 10
    }
}

How can I update one dict with another dict without overwriting other values/subdicts?

Darryl Lickt
  • 183
  • 2
  • 9

1 Answers1

2
config = {
    "a": {
        "hello": 1,
        "goodbye": 2,
    }
}

You can do:

config['a']['hello'] = 10

The updated config:

config = {
    "a": {
        "hello": 10,
        "goodbye": 2,
    }
}
Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94