Sort Data by path

Good Day,

how do i sort these data based on the number circled, if same number then sort by direction(x,y,z). If grasshopper, possible? Else, python? How do i do such in python? (9.6 KB)

Here it is with vanila GH. (9.8 KB)

P.S. You should move topic to Grasshopper category.