Skip to content

Instantly share code, notes, and snippets.

@aasmpro
Created March 24, 2022 21:53
Show Gist options
  • Save aasmpro/4f19a4d5886064ecc9e8ba7e7f7545f7 to your computer and use it in GitHub Desktop.
Save aasmpro/4f19a4d5886064ecc9e8ba7e7f7545f7 to your computer and use it in GitHub Desktop.
Script to add parranteses in certain positions in a line
text = input()
pairs_count = int(input())
pairs = []
for i in range(pairs_count):
pair = input().split()
pairs.append([int(i) for i in pair])
output = []
length = len(text)
for index in range(length+1):
for pair in pairs:
if index == pair[1]:
output.append(")")
for pair in pairs:
if index == pair[0]:
output.append("(")
try:
output.append(text[index])
except Exception as e:
pass
print("".join(output))
@aasmpro
Copy link
Author

aasmpro commented Mar 24, 2022

sample:

HelloWorld!
3
0 5
3 3
2 6

output:

(He(l)(lo)W)orld!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment