String.Contains

Hi,
I have been browsing a lot here lately because I cannot understand why Spring.Contains node is not behaving as expected. Or maybe I am not understanding how the node definitely works.

I am trying to filter strings that contains the letters “f” or “e” in a list. But the output is not what I expected. I hope someone can clarify.

Kindly refer to the attached image.

Thanks in advance.

@vbaac When you put the node on Longest lacing what Dynamo sees [f,e] as is:
[f,e,e,e,e,e,e]
So it gives the result you don’t want.

Try either of these instead

5 Likes

Hi @AmolShah ,

Thank you very much for the quick reply. You explained it very well ^^…
Another question though… Is it normal if setting the Cross Lacing of the String.Contains node slows down it’s operation? specially when there are a thousand strings involved?

Thank you ^^

1 Like

@vbaac Yes, it might slow things down if your dataset is large and you choose to go for Cross Product.
You can try minimizing the time by either using a python script or any of these nodes:

6 Likes

Yes, it is basically squaring the number of calculations. If you had two lists of 1,000 items in auto it would do 1,000 comparisons, but in cross product it’s doing 1,000 * 1,000 because each list is compared with every item from the other list. So, it can be substantially slower.

4 Likes

@AmolShah , Thank you for showing some alternative nodes… I am still trying to study python bit by bit… I will definitely try these nodes and use which is the best for me…

thank you guys for being so helpful ^^

1 Like

how to do the string contains in crossed lacing product with python?

Something like this simple code could work depending on your structure.

List1 = IN[0]
List2 = IN[1]

Result = []
 
For L1 in List1:
    if L1 in List2:
       Result.append(True)
    else:
        Result.append(False)

unexpected token says. I got a flatten list of strings and a flatten list of strings to check if they are contained in the other list
image
image

I was missing the colon after the for loop.

for i in List1:

it works as auto,long lacing of a dynamo node, I am expecting 4x times more results, it is not as the crossed lacing mode, also it says all false wich is not true in this case. I want to replace the node string.contains because it consumes a lot of memory RAM and time.

Base on the node I see before this one you have nested lists. Without seeing a full concept and data structure coming in nor example of what your wanting out I’m shooting in the dark. Those few quick lines were an example of how to test if a value was in a list, not a full blown stable node.

sorry I have to create an example to show, but search list are composed of 4 items strings, the full string list is composed by thousands of items strings. so I want to know if each of the 4 string items are in each of the thousands items list.

You would have to include a For loop for the “search” values as well. If the number of search values (4) is constant, you could also just write a conditional statement that includes all (4) values.

1 Like

You could also try the Archi-lab (i believe it is in this Package) String.Contains.
It handles multiple Strings (without needing to change the Lacing i believe).