This may be a dumb question, but I am stumped on this. The programing language is Python and I have a list of ordered pairs like this:
listX = [[1, 2], [3, 4], [2, 2], [0, 0]]
...and an adding function like this:
add(x, y): return x + y
Now what I'm trying to do is choose an ordered pair from the list with the lowest sum. I created a for... loop to do this, but I only get a meaningful answer if I compare the function's value to an integer. Example:
for r in listX:
if add(r) < {given integer}:
print r
else:
print "This pair is not less than {given integer}"
What could work is instead of comparing "add(r)" to an integer, is to compare it to the values of the rest of the list. Pseudocode example:
if add(r) < {add(r) of the other values in listX}:
However, I do not know how to implement this. This method could be entirely wrong as well, I don't know.
All input will be appreciated.
