Remove similar numbers in a list
<p>How do I remove numbers like 86.1 and 90.1 (or 86.2 and 90.2) from the following list?</p>

<pre><code>86.1      86.2       90.1      90.2
</code></pre>

<p>Define a threshold, iterate over the sorted numbers and add up the numbers within the threshold:</p>

<pre><code>numbers = [86.1, 86.2, 90.1,90.2]

threshold = 1
numbers = iter(numbers)
amount = last = next(numbers)
count = 1
result = []
for number in sorted(numbers):
    if number - last &gt; threshold:
        result.append(amount/count)
        amount = count = 0
    amount += number
    count += 1
    last = number
</code></pre>

<p>result.append(amount/count)</p>

python list python-2.7