Deep Merge Multiple YAML Config Files
Beginner Mode

Start your terminal to use beginner mode.

Scenario

Three YAML configuration files contain application settings with some overlapping keys. You need to merge them into a single configuration file where values from later files override earlier ones.

Task

Write a Python script at /home/interview/merge_configs.py that merges /home/interview/config1.yaml, /home/interview/config2.yaml, and /home/interview/config3.yaml (in that order) into /home/interview/merged_config.yaml. Later files should override values from earlier files, with deep merging for nested structures. Lists (arrays) should be fully replaced by the later file's value, not appended.

Note: The pyyaml package is already installed.

Example

If config1.yaml has:

database:
  host: localhost
  port: 5432
app:
  debug: true
  plugins:
    - auth
    - logging

And config2.yaml has:

database:
  host: prod-server
app:
  timeout: 30
  plugins:
    - auth
    - metrics

The merged result should be:

database:
  host: prod-server
  port: 5432
app:
  debug: true
  timeout: 30
  plugins:
    - auth
    - metrics

Note that plugins is fully replaced by config2's list, not merged or appended.

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →