PIXELBANKv9.1.0
Menu

Implement a simple prompt template engine.

Given a template string with {{variable}} placeholders and a set of key-value pairs, substitute all placeholders with their values.

Input:

  • Line 1: The template string
  • Line 2: N (number of variables)
  • Next N lines: key value (space-separated, value may contain spaces)

Output: The filled template string.

If a placeholder has no matching key, leave it as-is.

Example:

Input:
Hello {{name}}, you are {{role}}.
2
name Alice
role engineer
Output:
Hello Alice, you are engineer.
Reasoning:
  • The template string Hello {{name}}, you are {{role}}. is given with two placeholders: {{name}} and {{role}}.
  • A set of key-value pairs is provided: name = Alice and role = engineer.
  • The template engine substitutes the placeholders with their corresponding values, resulting in Hello Alice, you are engineer..
  • Since both {{name}} and {{role}} have matching keys, they are replaced; if a placeholder had no match, it would remain unchanged.

Constraints:

  • Placeholders use double curly braces: {{key}}
  • Keys are alphanumeric (no spaces)
  • Values may contain spaces
  • Unmatched placeholders remain unchanged
solution.py

Test Results

0/0
Run code to see test results.
Template Variable Substitution - Easy | PixelBank