Last active
October 10, 2018 20:50
-
-
Save niharika88/8eb8ecd430729f6caa647804bee1e011 to your computer and use it in GitHub Desktop.
The function called populate_template which takes in a template string e.g. " Hello {!first_name} - How are you?" and a hash of fields e.g { "first_name" : "John" } as arguments and returns the template string with the fields inserted in the correct place. It takes in 2 arguments: - template (String) - fields (hash / dictionary)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def populate_template(template, fields= {}): | |
| for key, value in fields.items(): | |
| if template.find(key): | |
| template_new = re.sub(key, fields[key], template) | |
| return template_new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment