PIXELBANKv9.1.0
Menu

Effective Environment After Layered ENV Instructions

Problem Statement

A Dockerfile sets environment variables across several ENV instructions; later ones override earlier keys. Compute the final environment.

Background

Each ENV instruction contributes one or more KEY=VALUE pairs. Applied top to bottom, a later assignment to the same key replaces the earlier value. The result is the merged mapping.

Your Task

def resolve_env(env_layers):
  • env_layers: list of dicts, each a set of KEY: VALUE from one ENV line, in order.
  • Return the final merged dict.

Input Format

  • env_layers (list of dicts).

Output Format

  • A dict.

Sample

print(resolve_env([{"A": "1", "B": "2"}, {"B": "9"}]))

Output:

{'A': '1', 'B': '9'}

Example:

Input:
print(resolve_env([{"A": "1", "B": "2"}, {"B": "9"}]))
Output:
{'A': '1', 'B': '9'}
Reasoning:
  • Start with an empty environment mapping to accumulate the final state.
  • Process the first layer {A:1,B:2}\{A: 1, B: 2\} by merging its key-value pairs into the current mapping, resulting in {A:1,B:2}\{A: 1, B: 2\}.
  • Process the second layer {B:9}\{B: 9\} by updating the existing mapping; since key BB already exists, its value is overridden from 22 to 99, while key AA remains unchanged.
  • The merged mapping after all layers is applied is {A:1,B:9}\{A: 1, B: 9\}.
  • The final output is {'A': '1', 'B': '9'}

Constraints:

  • Apply layers in order; later keys overwrite earlier ones.
  • Keys absent in later layers keep their earlier value.
  • Return the merged dict.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.