Skip to content

Instantly share code, notes, and snippets.

@opethe1st
Last active July 26, 2020 06:25
Show Gist options
  • Save opethe1st/41ee02d75233447e460b566932d4f111 to your computer and use it in GitHub Desktop.
Save opethe1st/41ee02d75233447e460b566932d4f111 to your computer and use it in GitHub Desktop.
import re
def solution(formatString, replacements):
formatString = re.sub(r'([^{]){(\d+)}}', r'\g<1>{\g<2>}}}', formatString)
formatString = re.sub(r'{{(\d+)}([^}])', r'{{\g<1>}}\g<2>', formatString)
try:
return formatString.format(*replacements)
except ValueError:
return ''
if __name__ == '__main__':
print(solution("A {{{0}} {2}} with {0} {1}.", ["fun", "activities", "party"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment