Search Function - GhPython

Hello Rhino Community,

I am currently working on a project in which I want to output a minimum Z coordinate from a large number of coordinate sets. To do this, I am searching for the corresponding x and y coordinates from a list of points. For this I decided to write a small GhPython script.
Unfortunately the program doesn’t work as I want it to (see attachment [simplified]). Do you know what I did wrong?

LG
Chris


I’m not so clear on exactly what it is that you want, but something like this would output the point with the minimum Z value.

a = sorted(Koords, key = lambda i: i.Z)[0]
2 Likes

Hey Adam,

thanks for your quick reply!
That’s exactly what it should do. So I originally had quite a few points that I split into the individual components (x, y, z). I have then the lowest Z coordinate out give me. At another point I need the coordinates x, y of my smallest Z-coordinate. For this the program is to serve these rauszugeben in that it searches the list.
Thanks for your help!

Chris

If you don’t need to sort the entire list, min and max also accept a key function.

a = min(Koords, key = lambda i: i[2])

You can use it with enumerate and a different key to retrieve the index of the minimiser.

I think you might have a problem however, because in Python you can’t index into a set.
Tuples would be a better choice for co-ordinates, or even a special class.

2 Likes