title: I need a function to return the first level parenthesized substring in python
body: <p>I have been using a code to remove a parenthesized substring, which goes like this;</p>
  <pre><code>def alkylrem(j):
      removed = ''
      paren_level = 0
      for char in j:
          if char == '(':
              paren_level += 1
          elif (char == ')') and paren_level:
              paren_level -= 1
          elif not paren_level:
              removed += char
      return removed
  </code></pre>
  <p>But I find this inadequate since I also need to retrieve the parenthesized substring and maybe store it in a global variable. Can I add an 'elif' statement to do that? or is there a better way to do this?</p>