def _paren_groups(source):
 count = 0
 start = 0
 result = []
 for pos in xrange(len(source)):
  if (source[pos] == '('):
   if (count == 0):
    start = pos
   count += 1
  if (source[pos] == ')'):
   count -= 1
   if (count == 0):
    result.append(source[start:(pos + 1)])
 return result

def _paren_groups ( source ) : count = 0 start = 0 result = [ ] for pos in xrange ( len ( source ) ) : if ( source [ pos ] == '(' ) : if ( count == 0 ) : start = pos count += 1 if ( source [ pos ] == ')' ) : count -= 1 if ( count == 0 ) : result . append ( source [ start : ( pos + 1 ) ] ) return result
split a string into parenthesized groups .