My Question is i have two list one is sorted and the another not so how can i get the not sorted index that eqaul to the sorted one
from math import sqrt as sq
Points = [(54,0), (4,6), (-1,6), (5,-7), (5,1)]
def closeest() :
a= list(int(sq(x[0]**2 + x[1]**2)) for x in Points)
a.sort()
print("The new list is:")
print(a)
print("The closest point is:")
# Here i need to get the value of Points index that equal to the first sorted a list
closeest()
Use your "distance" function as the key argument for whatever sorting function you use.
>>> Points = [(54,0), (4,6), (-1,6), (5,-7), (5,1)]
>>> from math import sqrt as sq
>>> dist = lambda point: int(sq(point[0]**2 + point[1]**2))
>>> max(Points, key=dist)
(54, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With