Any way to use a range as a key in a dictionary?
Carl Banks
pavlovevidence at gmail.com
Fri Mar 27 11:50:02 EDT 2009
On Mar 26, 11:02 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Dennis Lee Bieber <wlfr... at ix.netcom.com> writes:
>
> > ... v = theDict.get(x, NOT_RELEVANT)
> > ... if v is not NOT_RELEVANT:
> > ... print x, v
>
> I think you'd normally do this with
>
> if x in theDict:
> print x, v
Where does v come from?
> but the OP was asking about a different problem, involving looking up
> numeric ranges, which could conceivably be very large, thus the
> suggestions about interval trees and so forth.
The fact that the OP asked about what to do with the the other 65526
values suggests that he only wanted to use intervals to fill in the
gaps between meaningful values (thus having complete coverage over the
16-bit integer range). An interval tree would not be a good approach
for that situation.
Carl Banks
More information about the Python-list
mailing list