I have a list of points and I need to find if the points exist in a rectangle defined by the top-left and bottom-right corners. If all the points belong in the rectangle then the result is True, otherwise the result is False.
Here is my code but I am getting it wrong somewhere.
def Functn1(topLeft=(0,0), bottomRight=(0,0), pointList=[]):
x1 = topLeft[0]
y1 = topLeft[1]
x2 = bottomRight[0]
y2 = bottomRight[1]
xa = pointList[i][0]
ya = pointList[i][0]
xb = pointList[i][1]
yb = pointList[i][1]
lengthofList = len(pointList)
for i in range(lengthofList):
if ((xa > x1 and xb < x2) and (ya > y1 and yb < y2)):
#if ((x[i][0] > x1 and x[i][1] < x2) and (y[i][0] > y1 and y[i][1] < y2)):
#Also tried using this code but keep getting the same error
return True
else:
return False
Functn1((0,0), (5,5), [(1,1), (0,0), (5,6)]) #should get False
I am getting this error:
<ipython-input-153-669eeffdb011> in allIn(topLeft, bottomRight, pointList)
20
21 for i in range(lengthofList):
---> 22 if ((x[i][0] > x1 and x[i][1] < x2) and (y[i][0] > y1 and y[i][1] < y2)):
23 return True
24 else:
TypeError: 'int' object is not subscriptable