curriculum/challenges/english/blocks/daily-coding-challenges-python/6821ebda237de8297eaee792.md
Given a string that contains properly nested parentheses, return the decoded version of the string using the following rules:
decode("(f(b(dc)e)a)") should return "abcdef".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("(f(b(dc)e)a)"), "abcdef")`)
}})
decode("((is?)(a(t d)h)e(n y( uo)r)aC)") should return "Can you read this?".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("((is?)(a(t d)h)e(n y( uo)r)aC)"), "Can you read this?")`)
}})
decode("f(Ce(re))o((e(aC)m)d)p") should return "freeCodeCamp".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode("f(Ce(re))o((e(aC)m)d)p"), "freeCodeCamp")`)
}})
def decode(s):
return s
def decode(s):
while ')' in s:
close_index = s.index(')')
open_index = s.rindex('(', 0, close_index)
inner = s[open_index + 1:close_index][::-1]
s = s[:open_index] + inner + s[close_index + 1:]
return s