Stuck on lists

Hi guys,

Here’s another noob post. I’m trying to filter a list of things through another list of things in order to get only the elements I want and then go to town with them. I always get lost when sorting through cross product or levels and then not knowing how to go back to the previous list structure (the one with all the elements I’m searching through). See screenshot attached:

I’m sure this is rather simple but just wanted to also ask people here since a lot of us using dynamo are always querying, searching and sorting through the revit maze of stuff…What is your go to sorting/filtering strategy?

Thanks a lot

can you show all the output ?

It would certainly be helpful to see the outputs of the nodes or, even better, the graph itself.

Your String.Contains node will presumably be outputting a 2D list, with a list of booleans for each door which says whether the Hardware Set contains in turn any of your test list of strings. Assuming you want to filter the list between doors that contain any of your test strings and none at all then you could simply use List.CountTrue (@L2) which will total all the Trues in the sublist, then you can see whether it is greater than 0, and if so, one of your strings can be found in the Hardware Set. Use the > node to convert to a list of booleans which can then be fed with Auto lacing into List.FilterByBoolMask on the original list of doors. For example, using some dummy data with List.Shuffle simulating the Hardware Set values:

It’s worth pointing out a few other things:

  • When you use String.Contains you need to be careful, because any string that returns true for “HW-13” or “HW-10” will also return true for “HW-1”. Probably not an issue in this case as you want all that match.
  • You don’t need to use String from Object after the code block “HW” + X because that will be a string anyway. If your Hardware Set parameter is a Text field in Revit, then you also won’t need to use String from Object there either

Hope this helps,

1 Like

Use == with list levels @L1 then FilterByBoolMask with list level @L2 to get a list of elements grouped by Harware Set.

1 Like

Thanks for the help @Thomas_Corrie. That did it. Also good point about the risk in using List.Contains as a method to filter things out for this occassion. Generally speaking, should I avoid cross product lacing or is it the same to use the levels with lacing longest for cross referencing lists with lists? I found that both methods achieve the same results in this case.

Thanks again

1 Like

Just another option…

Thanks Nick. So using levels @L1 for the querying list will essentially give you one list per each querying object (in this case 3 lists of 10 items) and it will nest them within a list? Which would explain why you have to go one level deeper for the filtering and bring it back around?

In this case you get the same result from longest with @L2 on one input as you would from cross product

More or less. List levels basically let you control what Dynamo would consider as the input. Specifying an input @L2 means that Dynamo will count each item at list level 2 as a single input (whether it’s a list or a singleton) and iterate for each object a level 2. Dynamo will still use auto lacing to figure out how to handle other inputs unless you’ve specified list levels for them as well. Sometimes this means lacing is needed with list levels.

1 Like

This is kind of how grasshopper handles data trees