Hi Knut,<div><br></div><div>That exactly what I need.</div><div><br></div><div>Actually this <span class="Apple-style-span" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px; background-color: rgba(255, 255, 255, 0.917969); ">[0....200),[200....600),[600..</span><span class="Apple-style-span" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px; background-color: rgba(255, 255, 255, 0.917969); ">.1000)....etc....[100000, infinity]</span></div>

<div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">Should be rad as </font><span class="Apple-style-span" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px; background-color: rgba(255, 255, 255, 0.917969); ">[0, 200),[200, 600),[600, </span><span class="Apple-style-span" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px; background-color: rgba(255, 255, 255, 0.917969); ">1000)....etc....[100000, infinity]</span></div>

<div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br></font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">Thank you for code!</font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">Max</font></div>

<div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br></font><br>
<br><br><div class="gmail_quote">On Tue, Nov 15, 2011 at 5:06 PM, Knut Nesheim <span dir="ltr"><<a href="mailto:knutin@gmail.com">knutin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">On Tue, Nov 15, 2011 at 2:27 PM, Max Bourinov <<a href="mailto:bourinov@gmail.com">bourinov@gmail.com</a>> wrote:<br>
> I have a value X which is integer, and I have a list of ranges<br>
> [0....200),[200....600),[600...1000)....etc....[100000, infinity]<br>
<br>
</div>Hi Max,<br>
<br>
Some time ago I had to solve the exact same problem. What I wanted was<br>
fast lookups and low memory overhead. My data is not changing often.<br>
Storing each key and value in a structure where you could lookup based<br>
on key (dict, array or your own tuple), would require storing every<br>
possible key in the range, this was not acceptable for me.<br>
<br>
My solution was to implement a binary tree, where the key instead of<br>
being an exact key, is a range of keys. So the key could be {100, 200}<br>
and the value would be 'foo'. If you are searching for 101, the value<br>
returned is 'foo'. My implementation is on github[1]<br>
<br>
 [1]: <a href="https://github.com/knutin/tree_range" target="_blank">https://github.com/knutin/tree_range</a><br>
<br>
Regards<br>
<span class="HOEnZb"><font color="#888888">Knut<br>
</font></span></blockquote></div><br></div>