how would one sum a range of numbers within a certain value?
<p>I have an array of values like so</p>

<pre><code> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
</code></pre>

<p>Is there a pythonic way to sum all values within this array that are between a certain value? For example, if my range was 2.5-6, I would expect to get 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + 6 = 35.7. I'm also open to using numpy to solve this as well.</p>

<pre><code>&gt;&gt;&gt; nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
&gt;&gt;&gt; sum([n for n in nums if 2.5 &lt;= n &lt;= 6])
35.7
&gt;&gt;&gt; 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + 6
35.7
</code></pre>

python arrays numpy range