def zeroDepthSearch(expression, value):
 retVal = []
 depth = 0
 for index in xrange(len(expression)):
  if (expression[index] == '('):
   depth += 1
  elif (expression[index] == ')'):
   depth -= 1
  elif ((depth == 0) and (expression[index:(index + len(value))] == value)):
   retVal.append(index)
 return retVal

def zeroDepthSearch ( expression , value ) : retVal = [ ] depth = 0 for index in xrange ( len ( expression ) ) : if ( expression [ index ] == '(' ) : depth += 1 elif ( expression [ index ] == ')' ) : depth -= 1 elif ( ( depth == 0 ) and ( expression [ index : ( index + len ( value ) ) ] == value ) ) : retVal . append ( index ) return retVal
searches occurrences of value inside expression at 0-depth level regarding the parentheses .