Based on your description and example input I have interpreted that as you should take the min of the two differences, rather than the difference of them. Then you'll pick the element that has the smallest change in either of the two numbers.
To go in the right direction you can just check whether the element you are currently at is larger or smaller than the target
Doing that you'll get the following:
elements = [ [320, 80],
[300, 70],
[300, 80],
[270, 75],
[260, 70],
[280, 70]
]
def nextLogicalElement(target, bigger=True):
bestScore = 0
bestMatch = []
for e in elements:
score = min(abs(target[0] - e[0]), abs(target[1] - e[1]))
if bigger and target[0] > e[0] or not bigger and target[0] < e[0]:
continue
if not bestMatch or score < bestScore:
bestMatch = e
bestScore = score
return bestMatch
Output:
>>> print nextLogicalElement([315, 80], bigger=True)
[320, 80]
>>> print nextLogicalElement([275, 70], bigger=False)
[260, 70]