Fill a Message Template

Easy ⏱ 8 min 82% acceptance ★★★★☆ 4.2
Write a function fill_template(template, values) that takes a string template containing {}-style placeholders (using str.format syntax, e.g. "Order {order_id} shipped to {city}") and a dict values mapping placeholder names to their values, then returns the fully substituted string.

Examples

Example 1
Input
fill_template("Order {order_id} shipped to {city}", {"order_id": 501, "city": "Pune"})
Output
'Order 501 shipped to Pune'
Explanation

Both placeholders substituted from the dict.

Constraints

  • Every placeholder name in template has a matching key in values.

Topics

Input & Outputstring formatting

Companies

SalesforceServiceNow

Hints

Hint 1

`template.format(**values)` expands the dict as keyword arguments.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.