Fill In Template Placeholders

Medium ⏱ 12 min 54% acceptance ★★★★☆ 4.3
Write fill_template(template, values) that takes a template string containing {key} placeholders and a dictionary values, and returns the template with every placeholder replaced by the string form of its corresponding value.

Examples

Example 1
Input
template = 'Hello {name}, you have {count} new messages.', values = {'name': 'Aman', 'count': 3}
Output
'Hello Aman, you have 3 new messages.'
Explanation

'{name}' becomes 'Aman' and '{count}' becomes '3'.

Constraints

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

Topics

StringsTemplates

Companies

SalesforceServiceNow

Hints

Hint 1

Loop over `values.items()` and call `template.replace('{' + key + '}', str(val))` for each one.

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