title: How to reformat a string of string operations and get its result
body: <p>I have written a code that aims to expand a string. For example:
  <code>solve("3(ab)") = "ababab" -- "ab" repeats 3 times</code> </p>
  
  <p>I managed to rewrite the input string into a more readable way. However, I haven't figured out a way to reformat this string such that python can execute the operation. I am unfamiliar with the .format methods.</p>
  
  <pre><code>def solve(st):    
      rewritten = ''
  
      for i in range(len(st)-1):    
          if st[i].isdigit():
              if st[i+1] == '(':
                  rewritten += st[i] + '*' 
              else:
                  rewritten += st[i]
  
          elif st[i].isalpha():
              if st[i+1] == '(' or st[i+1].isdigit():
                      rewritten += st[i] + '+'   
              else:
                  rewritten += st[i]
          else:
              rewritten += st[i]
  
      rewritten += st[-1]      
      return rewritten
  
  solve("k(a3(b(a2(c))))") #returns 'k+(a+3*(b+(a+2*(c))))', ideally 'kabaccbaccbacc'```
  </code></pre>