Python: Round to next predefined integer in list
<p>I have a Python list of predefined integers:</p>

<pre><code>intvals = [5000, 7500, 10000, 20000, 30000, 40000, 50000]
</code></pre>

<p>I need to round down and up to the next lower/higher value in the list. So for example, given the number <code>8000</code>, the result should be <code>[7500, 10000]</code>. For <code>42000</code>, it should be <code>[40000, 50000]</code>. I am wondering if there is an easy way to do it.</p>

<p>My idea would be to create a function that has two loops - one that decreases a value -1 until it finds one in the list, and one that increases the value by 1 until it finds the higher match. This would work but maybe there is a better solution?</p>
