Elegant way to look at a +/- range surounding a particular value in Python
<p>I'm working with a large set of data in a spreadsheet using the openpyxl library.</p>

<p>I need to find certain temperature values and then look at other cells based on that temperature.</p>

<p>the problem is that my temperature fluctuates a bit in its measurements but I don't really care about this.</p>

<p>For example, if I want to look at the data when it's 25 degrees out, what I really want is the data ranging from about 24 - 26 degrees. And I need to do this for a number of temperatures.</p>

<p>I know how to do this in a rather messy iterative fashion like this:</p>

<pre><code>for num in [5,10,15,20,25]:     
    if temp &gt; num -1 and temp &lt; num + 1:        
        #do things
</code></pre>

<p>but this just feels messy to me, is there any cleaner way to do it? Something like checking if temp is within a certain error of num?</p>