title: How can I perform conditional splitting in python?
body: <p>I want to split string with comma when comma is not surrounded by ().</p>
  
  <pre><code>str = r"a,b,c,test(1,2,3),g,h,test(2,4,6)"
  </code></pre>
  
  <p>Desired split</p>
  
  <pre><code>split = ['a','b','c','test(1,2,3)','g','h','test(2,4,6)']
  </code></pre>
  
  <p>how can I do using regex python</p>
  
  <p>My efforts so far,</p>
  
  <pre><code>splits = [m.start() for m in re.finditer(',', string_i)]
  
  paranths = {10: 16, 26: 32} #using function
  
  lst = []
  
  first = 1
  for l in splits:
      print l
      for m in paranths:
          if (l &lt; m and l &lt; paranths[m]):
              #print m,':',l,':',paranths[m]
              lst.append(string_i[first:l])
              first = l+1
              break
              break
  </code></pre>