-2

I have a dict a = {'zgd': 0, 'zjd: 748'} and another dict b = {'jds': 748, 'jdl': 100}

How can I combine b into a with another key, 'gzbx', like:

{'zgd': 0, 'zjd': 748, 'gzbx': {'jds': 748, 'jdl': 100}}?

I'd like the simplest Python code to complete it.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • Have you looked into using the update method in the dictionary class? Here is an example usage: https://www.w3schools.com/python/ref_dictionary_update.asp – tschmitz Jul 26 '23 at 04:01
  • 1
    @tschmitz You don't need the `update` method for what the OP wants. A simple assignment to the specified key will do. – blhsing Jul 26 '23 at 04:07
  • Does this answer your question? [How can I add new keys to a dictionary?](https://stackoverflow.com/questions/1024847/how-can-i-add-new-keys-to-a-dictionary) – mkrieger1 Jul 31 '23 at 08:18

1 Answers1

0
a['gzbx'] = b

Here's a link to python's documentation, which should be helpful for basic syntax.

Eric C
  • 16
  • 2