class ClosestDict(dict):

    def get(self, key):
        key = min(iter(self.keys()), key=lambda x: abs(x - key))
return dict.get(self, key)
d = ClosestDict({(10): 3, (100): 2, (1000): 1})
Custom dictionary lookup in Python