Sort by the distance from multiple points to one point

how to write the red circle

Mar.17,2021

from functools import partial
import math

points = [(1, 2), (3, 4), (5, 6), (7, 8)]
pt = (4, 3)

def distance(p1, p2):
    return math.hypot(p1[0] - p2[0], p1[1] - p2[1])

points.sort(key=partial(distance, pt))

there is no need to use partial functions

points.sort(key=lambda i: math.hypot(i[0] - pt[0], i[1] - pt[1])) -sharplambda

and list.sort has no return value. If you write and print like that, None, newlist = sorted (list) is the one with return value

.

you can write so much that you can't write the red circle.
x1, y1 = p1
x2, y2 = p2

Menu