title: How to remove highly differentiated element from a list of numbers
body: <p>I have some lists where each list contains similar numbers (tolerance: +/-10%). But sometimes the list also contains noises: elements with large differences from the other 'normal' elements.  </p>
  
  <p>Here are some samples:</p>
  
  <pre><code>a = [100, 102, 99, 225, 105]
  b = [150, 142, 24, 153, 147, 315, 149]
  c = [34, 33, 31, 80, 32, 30]
  </code></pre>
  
  <p>What I want is a simple way to automatically remove these noises. From the first list, the <code>225</code> should be removed. From the second list, the <code>24</code> and <code>315</code> should be removed. From the last list, the <code>80</code> should be removed. Currently, my code is this:</p>
  
  <pre><code>import math
  
  def foo(numbers):
      numbers_filtered = []
      for i, n in enumerate(numbers):
          n_upper = n + (n * 0.1)
          n_lower = n - (n * 0.1)
          similar = 0
          for j, m in enumerate(numbers):
              if i == j:
                  continue
              if m &gt;= n_lower and m &lt;= n_upper:
                  similar += 1
          if similar &gt;= math.ceil(len(numbers) / 2.0):
              numbers_filtered.append(n)
  
      print('%s -&gt; %s' % (numbers, numbers_filtered))
  
  a = [100, 102, 99, 225, 105]
  b = [150, 142, 24, 153, 147, 315, 149]
  c = [34, 33, 31, 80, 32, 30]
  foo(a)
  foo(b)
  foo(c)
  </code></pre>
  
  <p>But I'm not satisfied with the code since I'm expecting much simpler code. Could you suggest me the easier way to accomplish this task?</p>