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?

SORT.gh (9.6 KB)

Here it is with vanila GH.

SORT_re.gh (9.8 KB)

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