Any way to use a range as a key in a dictionary?

Paul Rubin http
Fri Mar 27 07:02:21 CET 2009

Dennis Lee Bieber <wlfraed at> 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

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.

More information about the Python-list mailing list