title: Splitting a sentence into two halves
body: <p>I have the following structure of sentences:</p>
  
  <pre><code>sent = '(1 (2(2 The) (2 Rock)) (2(2 is) (2 big)) )'
  </code></pre>
  
  <p>where numbers mean sentiment assessment, and the other part in brackets is a word.
  What I want to do: is to represent sentence as a tree (each parent has maximum 2 children). For this I need a function, that splits a sentence into halves.</p>
  
  <p>I came up with the following solution:</p>
  
  <pre><code>def sent_div(sent):
      temp_ind = []
      finish_ind = []
      slash = 0
      back_slash = 0
      for i in range(1,len(sent)):  
          if sent[i] == '(':
              slash +=1
              temp_ind.append(i)
          elif sent[i] == ')':
              back_slash +=1
              finish_ind.append(i)
  
          if slash == back_slash and slash != 0:
              left = sent[min(temp_ind):i+1]
              break
  
  
      temp_ind = []
      slash = 0
      back_slash = 0 
      for i in range(max(finish_ind) + 1,len(sent)):  
          if sent[i] == '(':
              slash +=1
              temp_ind.append(i)
          elif sent[i] == ')':
              back_slash +=1
              #finish_ind.append(i)
  
          if slash == back_slash and slash != 0:
              right = sent[min(temp_ind):i+1]
              break
  
  
      return left,right   
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>left,right = sent_div(sent)
  
  print(left)
  '(2(2 The) (2 Rock))' 
  
  print(right)
  '(2(2 is) (2 big))')
  
  sent_div(right)
  ('(2 is)', '(2 big)')
  </code></pre>
  
  <p>But it looks ugly. Can you suggest any improvements to my code?</p>