Created
July 26, 2020 06:39
-
-
Save opethe1st/84b943ad76d4927afd027425d1260d4c to your computer and use it in GitHub Desktop.
This file contains 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
def solution(template, replacements): | |
ans = '' | |
i = 0 | |
iterator = TemplateIterator(template) | |
error = False | |
while template.hasnext(): | |
if is_literal_brace(template): | |
ans += '{' | |
template.advance(2) | |
elif is_in_brace(template): | |
number, error = template.advance_past('}') | |
replacement, error = get_replacement(replacements, number) | |
if error: | |
return '' | |
ans += replacement | |
else: | |
ans += template.current() | |
template.advance(1) | |
return '' if error else ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment