title: Dropping data in range buckets
body: <p>I have two dimentional data stored in a sorted list of tuples, as follows:</p>
  
  <pre><code>data = [(0.1,100), (0.13,300), (0.2,10)...
  </code></pre>
  
  <p>The first value in each tuple, the X value, only occurs once for the list of tuples. In other words, there can only be one value for 0.1 etc. </p>
  
  <p>I then have a sorted list of buckets. A bucket is defined as a tuple containing a range and an id, as follows:</p>
  
  <pre><code>buckets = [((0,0.14), 2), ((0.135,0.19), 1), ((0.19,0.21), 2), ((0.19,0.24), 3)...
  </code></pre>
  
  <p>A range is with respect to the X axis. So, the id 2 has two buckets above and ids 1 and 3 have only one, respectively. The first bucket for id 2 has a range from 0 to 0.14. Please note that buckets can overlap. </p>
  
  <p>So, I need an algorithm which drops the data into the buckets and then adds up the scores. For the data above, the result would be:</p>
  
  <pre><code>1:0
  2:410
  3:10
  </code></pre>
  
  <p>Notice how each piece of data is caught by a bucket associated with the id 2, hence it gets the score <code>100+300+10=410</code>.</p>
  
  <p>How might I write an algorithm to do this?</p>