Skip to content

Instantly share code, notes, and snippets.

@opethe1st
Created July 26, 2020 06:39
Show Gist options
  • Save opethe1st/84b943ad76d4927afd027425d1260d4c to your computer and use it in GitHub Desktop.
Save opethe1st/84b943ad76d4927afd027425d1260d4c to your computer and use it in GitHub Desktop.
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