def nearest_key(self, key):
    if not isinstance(key, tuple):
        key = key,
nk = min((k for k in self), key=lambda k: NearestDict.__dist(key, k))
return nk

def __missing__(self, key):
    if not isinstance(key, tuple):
        key = key,
if len(key) != self.ndims:
    raise KeyError('key must be %d dimensions' % self.ndims)
return self[self.nearest_key(key)]
Найти ближайшего целого числа в dict