Say I have an OrderedDict
:
a = OrderedDict([(5, 'a'), (7, 'b'), (10, 'c')])
Is there an efficient way to get the first value whose key exceeds a certain threshold, without looping over all keys?
Examples:
>>> get_first(a, 6)
'a'
>>> get_first(a, 3)
None
>>> get_first(a, 8)
'b'
I would like to avoid having to implement binary search myself. Is there an efficient out-of-the-box implementation available?