Search notes:

Python: merge two dictionaries

The following example tries to demonstrate how two dictionaries can be merged.
dict_1 = {'x'  : 'eggs', 'y'    : 'why'  , 'num': 99}
dict_2 = {'num':  42   , 'hello': 'world'           }

dict_merged = {**dict_1, **dict_2}

for k, v in dict_merged.items():
    print(f"{k} = {v}")
Github repository about-python, path: /types/dict/merge.py
When executed, this script prints:
x = eggs
y = why
num = 42
hello = world
Note, the value of the num key of dict_2 has overwritten the corresponding value of dict_1.

See also

The update() method of a dict updates a dict with the key/value pairs of another dict.
Arguments in def with two stars

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199808, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/types/dict/merge(57): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78