Is it possible to do something like:
r = {range(0, 100): 'foo', range(100, 200): 'bar'}
print r[42]
> 'foo'
So I would like to use a numeric range as part of a dictionary index. To make things more complicated I would also like to use multi-indexes like ('a', range(0,100))
. So the concept should be ideally expandable to that. Any suggestions?
A similar question was asked as here, but I am interested in a comprehensive implementation as opposed to the different approaches of that question.