Arrange points in branches

hi everybody!
I’m kinda newbie with grasshopper. I’m designing 2 wavy bookshelves for a flat. I’m doing it with grasshopper and I scripted an algorithm that works creating a point grid than I connected points using a nurbs curve component and it works. the problem is that I cannot arrange the sublists giving elements the correct orded (for the second bookshelf) while for the first one everything works fine. can anyone help me??
files attached
thank you so much in advance!

unnamed.gh (26.2 KB)

Here’s one way. Sorting by similar Y, then by Z.

Re_unnamed.gh (7.1 KB)

1 Like

it worked beautifully. thank you so much! you saved my life! :smile: