title: Python program to check matching of simple parentheses
body: <p>I came across this exercise of checking whether or not the simple brackets &quot;(&quot;, &quot;)&quot; in a given string are matched evenly.</p>
  <p>I have seen examples here using the stack command which I haven't encountered yet. So I attempted a different approach. Can anyone tell me where I am going wrong?</p>
  <pre><code>def matched(str):
      ope = []
      clo = []
      for i in range(0,len(str)):
          l = str[i]
          if l == &quot;(&quot;:
              ope = ope + [&quot;(&quot;]
          else:
              if l == &quot;)&quot;:
                  clo = clo  + [&quot;)&quot;]
              else:
                  return(ope, clo)
      if len(ope)==len(clo):
          return True
      else:
          return False
  </code></pre>
  <p>The idea is to pile up &quot;(&quot; and &quot;)&quot; into two separate lists and then compare the length of the lists. I also had another version where I had appended the lists ope and clo with the relevant I which held either ( or ) respectively.</p>