Question: 4. Implement function, q4(L, goalX, goalY), that takes a non-empty list, L, of [x,y) pairs, and two goal numbers, and returns tuple (closestXY, XorY) where

 4. Implement function, q4(L, goalX, goalY), that takes a non-empty list,

4. Implement function, q4(L, goalX, goalY), that takes a non-empty list, L, of [x,y) pairs, and two goal numbers, and returns tuple (closestXY, XorY) where closestXY is the item from L whose x distance from goal X or whose y distance from goalY is the minimum among all distances, and XorY is 'x' if x distance is minimized and 'y' otherwise. You may assume there is a unique answer. Note: You may not use built-in min or max functions. Examples: q4([[4, 4], [10, 10]], 1, 8) should return ([10,10], 'y'). q4 ([[10, 25], [2, 2], [49, 200]], 50, 8) should return ([49,200], 'x')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!