class translatedDictList(object):

    def __init__(self, dictList, key):
        self.dictList = dictList
self.key = key

def __getitem__(self, item):
    return self.dictList[item][self.key]

def __len__(self):
    return self.dictList.__len__()

def getNearest(self, symbolList, pos, maxDistance):
    translatedList = translatedDictList(symbolList, 'x')
splitIndex = bisect.bisect(translatedList, pos[0])
minIndex = bisect.bisect(translatedList, pos[0] - maxDistance)
maxIndex = bisect.bisect(translatedList, pos[0] + maxDistance)
leftElement = min(symbolList[minIndex:splitIndex], key=lambda n: abs(n['x'] -
    pos[0]) + abs(n['y'] - pos[1]))
rightElement = min(symbolList[splitIndex:maxIndex], key=lambda n: abs(n['x'
    ] - pos[0]) + abs(n['y'] - pos[1]))
return leftElement, rightElement
print(getNearest(self.symbolsSorted, (1200, 1500), 1000))
Get closest element from list of dictionaries