String.StartsWith Node - Multiple Substrings

I want to filter a list by the first letter. This setup works with a single string, but how do I enter more? I want to filter by letters “A”, “D”, “T”, and “S”. I tried a code block, but it failed.

Instead of a List.Map, use the node itself and leverage lacing and list levels.

@L1 for the ‘search for’ input will iterate over all the items in the primary list for the first search for, then the second, then the third…

You may want to force lacing set to longest incase of a nested list.

2 Likes

Hello, here it is, but less effective


code block:

rep=="a"||
rep=="t"||
rep=="v"||
rep=="s"?true:
false;

Python script:

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
data=IN[0]

container=[]
for i in data:
    if i[:1]=="a" or i[:1]=="t" or i[:1]=="v" or i[:1]=="s":
        r=True
        container.append(r)
    else:
        r=False
        container.append(r)        
OUT = container

Cordially
christian.stan

1 Like

Thanks Jacob, I will consider that. I did have a solution which was simply to copy the group for each letter. Seems lame, but it works. Then I used List.Create to combine the 4 filtered lists. Image and full DYN are attached if you wanted to see it.


z-test-vs-filtered.dyn (69.7 KB)

Thanks Christian. I may attempt your technique if I need it. I did come up with a crude solution.

1 Like

Or substitute the third party AnyTrue node for List.Contains with true as input (and keep list @L2)

2 Likes

I’d stay away from this method as it’ll be less robust and a fair bit slower on larger data sets.

I had he list levels backwards for the StartsWith before - you want the the string input to be @L1, auto lacing should suffice but your structure may requrie longest and/or setting the ‘search for’ to @L2. As Hamish showed cross product can also work for simple lists, but if things get more complex adjusting the list levels will work.

This will give you a boolean for each search term in each word, which you can then set to utilize the custom node or the out of the box “List.AnyTrue” node set to @L2 (I’d use the OOTB one to remove the dependency and increased speed due to the node type).

1 Like

Thanks Jacob. I may update the DYN with your method.