Skip to content
C

Merge Two Dictionaries

Mediumpython

Merge two dictionaries into one. If a key exists in both, the second dictionary's value should win.

Input format: each dictionary is given on its own line as comma-separated key:value pairs, e.g. a:1,b:2.

Approach: parse each line into a real dictionary, then merge them with dictionary unpacking {d1, d2} — keys from d2 override matching keys from d1.

Input: Two lines, each a comma-separated list of key:value pairs (values are whole numbers), e.g. a:1,b:2.

Output: One line: the merged dictionary, printed in Python dict format.

Input (stdin)

Output

Run your code to see output here...