PIXELBANKv9.1.0
Menu

Problem Statement

Merge and manipulate dictionaries.

Background

Python dictionaries support:

  • Access: d[key] or d.get(key, default)
  • Update: d[key] = value or d.update(other_dict)
  • Keys/Values: d.keys(), d.values(), d.items()
  • Merging (Python 3.9+): d1 | d2

Your Task

Write a function merge_dicts(dict1, dict2) that merges two dictionaries.

Merge Rules

  • If a key exists in both, sum the values (if numeric) or concatenate (if strings)
  • Keep unique keys from both dictionaries

Output Format

Return the merged dictionary.

Example:

Input:
dict1 = {"a": 1, "b": 2, "c": "hello"}, dict2 = {"b": 3, "d": 4, "c": " world"}
Output:
{'a': 1, 'b': 5, 'c': 'hello world', 'd': 4}
Reasoning:

'a' only in dict1, 'b' in both (2+3=5), 'c' in both (concat), 'd' only in dict2

Constraints:

  • Values are either numbers (int/float) or strings
  • For numbers, sum them; for strings, concatenate
solution.py

Test Results

0/0
Run code to see test results.