Using Binary Search, write a function in Python named length_of_line, which takes two inputs: points_lists – The list containing nested lists of starting and ending x and y coordinates of different lines. For e.g: [[(x1, y1), (x2, y2)], [(x1, y1), (x2, y2)], [(x1, y1), (x2, y2)], [(x1, y1), (x2, y2)]]. length – The length of a line. Now determine, if any line present in the points_lists has a same length as that of required length.Return the index of that line. If the line is not found, return -1. Hint: Estimate the length of a line with the help of the distance formula. test cases below: >>> length_of_line([[(2,4),(4,6)], [(1,2),(4,6)], [(4,0),(6, 6)]], 5.0) 1 >>> length_of_line([ [(2,4),(4,6)], [(1,2),(4,6)],[(4,0),(6, 6)]], 6.32) 2 >>> length_of_line([ [(2,4),(4,6)], [(1,2),(4,6)],[(4,0),(6, 6)]], 1.0) -1
Using Binary Search, write a function in Python named length_of_line, which takes two inputs:
points_lists – The list containing nested lists of starting and ending x and y coordinates of different lines. For e.g: [[(x1, y1), (x2, y2)], [(x1, y1), (x2, y2)], [(x1, y1), (x2, y2)], [(x1, y1), (x2, y2)]].
length – The length of a line.
Now determine, if any line present in the points_lists has a same length as that of required length.Return the index of that line. If the line is not found, return -1.
Hint: Estimate the length of a line with the help of the distance formula.
test cases below:
>>> length_of_line([[(2,4),(4,6)], [(1,2),(4,6)], [(4,0),(6, 6)]], 5.0)
1
>>> length_of_line([ [(2,4),(4,6)], [(1,2),(4,6)],[(4,0),(6, 6)]], 6.32)
2
>>> length_of_line([ [(2,4),(4,6)], [(1,2),(4,6)],[(4,0),(6, 6)]], 1.0)
-1
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images