Python sort points per distance to curve

Hello,
I’m trying to project points on 4 curves then remove the farthest point.
I wrote this:
image

Why is list not callable? how do I sort a list of points per distance?

Hi,

I believe the key argument of sort() expects a function, not a list.
Alternatively, you could sort your P1 list with the values of D1 like so:

sorted_pts = [pt for _, pt in sorted(zip(D1, P1), reverse=True)]
2 Likes

To sort your list with key you would need to define a function eg myfunc which takes a single argument: a point from the list, and returns the distance and use key=myfunc.
Graham

1 Like

Indeed. In C# this could be (or use OrderByDescending):

1 Like

You could also remove the farthest point without sorting:


210108_RemoveFarthestPoint_00.gh (5.8 KB)

3 Likes

Thanks everyone that was super helpful! I was using sort like the grasshopper component

2 Likes