title: Check if a list of numbers is in a certain range?
body: <p>I try to discretize some numbers, by looking if they are in a given range, and then assign a number based on the range, however the result which I get is not exactly correct.</p>
  
  <p><code>mapp</code> is the a dictionary of which defines ranges, and the values which correspond to the given range. </p>
  
  <p><code>lst</code> is the list of numbers that I want to match against those ranges, and assign identifiers to them</p>
  
  <pre><code>mapp = {(0,100): 1, (100,400): 2, (400,800): 3}
  
  
  lst = [3.5, 5.4, 300.12, 500.78, 600.45, 900.546]
  
  
  def discretize(mapping_dict, list_of_values):
      print "\n"
      location = []
      for x in sorted(list_of_values):
          for (lower_bound,upper_bound),value in mapping_dict.items():
              if round(x) in range(lower_bound,upper_bound):
                  print round(x), "yes", value
  
                  distance = mapping_dict[(lower_bound,upper_bound)]
                  location.append((distance))
  
  
          else:
              print round(x), "no"
  
              distance = len(mapping_dict.items())+10
              location.append((distance))
  
      return location
  </code></pre>
  
  <p>The result which I expect is: <code>[1, 1, 2, 3, 3, 13]</code> , however that's not what I get.</p>
  
  <p>This is the actual result which I get, which is incorrect:</p>
  
  <pre><code>4.0 yes 1
  4.0 no         #wrong!
  5.0 yes 1
  5.0 no         #wrong!
  300.0 yes 2
  300.0 no         #wrong!
  501.0 yes 3
  501.0 no         #wrong!
  600.0 yes 3
  600.0 no         #wrong!
  901.0 no         #CORRECT
  
  [1, 13, 1, 13, 2, 13, 3, 13, 3, 13, 13]
  </code></pre>
  
  <p>I get <code>no</code> at <code>4.0</code> which is not correct, etc, etc.</p>
  
  <p>Where is the problem?</p>
  
  <p>Thanks</p>