title: How can I use sum in python for specific values in a list?
body: <p>I have a text file that looks like this; the values are tab separated: </p>
  
  <pre><code>diamond orange pear loc1  .  +    0.0  0.0  0.0  0.0  1.0 1.2  3.4 
  diamond orange pear loc2  .  +    1.0  0.0  0.0  0.0  1.0 1.2  2.3
  diamond orange pear loc3  .  +    2.0  0.0  3.0  0.0  0.0 0.0  1.4  
  # ......
  </code></pre>
  
  <p>For each line in the file I want to make a ratio of the sum of the first 3 values divided by the sum of the last 4 values.  The output would look like: </p>
  
  <pre><code>diamond orange pear loc1  .  +    0 
  diamond orange pear loc2  .  +    0.22
  diamond orange pear loc3  .  +    4.28 
   ......
  </code></pre>
  
  <p>I would like to do this in python. </p>
  
  <pre><code>with open('/path/to/file/') as inFile:
      inFile.next()
      for line in inFile:
          data = cols[6:]
          data = map(float,data)
  
          sum_3 = [sum[for x in x data[0:3]]
          sum_last = [sum[for x in x data[4:7]]
          average = sum_3/sum_last 
  </code></pre>
  
  <p>This doesn't work, and I was hoping if I could get some advice? </p>