# How to separate and order points by z & x coordinate (for connecting by polylines + lofting)?

Hi there,

I’m struggling with a what is surely a very straight forward task…

I have a list of points which I want to split into sublists which group those located at the same z coordinate (Image 1)

I then need to order the points in those lists by their x coordinate in order to draw a clean polyline between them.

An old post (https://www.grasshopper3d.com/forum/topics/split-list-with-point-of-same-coordinates) addressed this issue back in 2014 but (strangely) the code had issues and as you can see in my screenshots, doesn’t appear to fare any better with my points - points are left out/missing (Images 2 & 3)

Thanks in advance for any assistance!
Nathan

Hi Nathan,

Here is script. check if this is what you want.
sortPts.gh (6.2 KB)

I know it might make things complex with Python but since I am practicing it, that`s way I wanna do.

But, I donot know how to build sort pts by its X-value and divide list into a tree structure as showed below.
Any expert can help me finish the code?
Thanks so much!

have a look here:

Thanks Lei! Unfortunately, it appears this solution also doesn’t want to work on my points…all the green one are missed. (See Image 4)

Yes I have, thanks!
I think I miscommunicated the problem - in fact I have less of an issue with “sorting” the points and more of an issue with splitting them into different lists accordingly. Then there’s the biggest issue which is the sorting process which strangely omits certain points…both in the script posted
by Lei above and in that from the 2014 forum post.

Hi Nathan,

The problem you showed first is about the input list ONLY has 4 positions however yours need more positons.
pls check the modified code.
sortPts.gh (7.1 KB)

Hi Amir,

All different with what I wanna do.
pls check below:

listPts = rs.coercePoints3d(input)
#is it possible use sorted() function like:
sorted(listPts, key = listPts.x)
#the syntax is bad but for address the idea that: I want use sort() or sorted() function to sort a point3d list by its x or y value.

I will have a look, thank you Lei !