How to filter nested lists


I am trying to get specific elements in a list of lists…

GOAL: Get all the family elements (index 0 of each list) that have a point with a positive y coordinate.
Ex. 6 list, 7 list and 8 list but not 1,2,3,4, or 5.

I basically want to get all the elements in index 0 and filter by a condition in index 1. Then return a single list of familes.

Let me know if you guys need further clarfication.

Another way to word this is ,
To filter the list by all the families if the point y coordinate is not negative… if it is not negative, then returning the family element.

Use getItemAtIndex with the correct list level input to get the points.

Get the Y component of the point.

Check if negative (<0)

Filter the original list.

Use getItemAtIndex with the correct list level input to get the families.

1 Like

Is there any way you could show me this with an example please? Still struggling… Thank you!

You need to split the lists into points and families separately. Run the condition on the points and then filter the families. Since everything is indexed the same (points match families) you can handle both lists separately without worrying about matching up values.


This would make sense, however, when I filter the Point list it messes up the indexes. Now they don’t match up with the families…

You can just get the y-value and check to see if it’s negative.
your_points.Y < 0;

Either way, you want to filter the families, not the points (unless you need them for something else in which case you can filter both).

1 Like

not at the cpu but I think this designscript should do the trick:
lists = List.Transpose(inputList); result = List.FilterByBoolMask(lists[0],lists[1]<0)[“in”];

1 Like

Hello, you forgot the Y component, with the phone

lists = DSCore.List.Transpose(inputList);
result = DSCore.List.FilterByBoolMask(lists[0],lists[1].Y<0)["in"];

Cordially
christian.stan

1 Like

Great catch. :slight_smile:

1 Like