Grasshopper contour and sort list

Hi I’d like to sort group of lines With a range of z-axis

For example, I want to extract lines 3 to 17 from the top of line5

I used sort list from z vector and list item but it doesnt work.
How do I write a script?

Rheotomic_Surfaces (32.5 KB)

The outputs from Contour are already sorted in the Z direction, just have to select which branches you want.

With a simple tree structure like this, you can also use Flip Matrix

Thanks for the detailed explanation.