Maximum with `by` keyword

I think you might want argmax(f, A) which returns the value x in A for which f(x) is maximized. So in your case this could be maxtuple = argmax(first, v).