Script used to work, now it doesn't and I can't figure out why!

I’ve used this script for a long time. Worked great.
The part that’s broken is when it takes a list of two strings and searches a longer list for the existence of those strings. In this case, the items show up at indices 261 and 268. But when the List.Contains runs, it doesn’t show the match at 261. Only at 268. (See over on the right side of the graph where the Watch node is hanging below the group)

I made a simpler version of the same setup and it worked fine. I don’t get why it’s not matching 261 like it used to.

Don’t use longest lacing. Use list levels to check each name separately.

1 Like

Thanks!
I could get it to work with a string.contains and list levels as shown (and then flatten the list), but not with list.contains. Out of curiosity, what would the list levels have to be to use list.contains?

And why does this work? Isn’t it the same scenario?

What list levels were you using with List.Contains? Also, make sure those parameters you get with String.Contains are correct. Flattening your lists is going to remove the correct list structure. You want to apply both lists as a mask to get both parameters that match.

You need to understand what Longest Lacing does. Longest lacing forces a matching list length by repeating the last item as needed. In the first example, "THIS" gets compared with "THIS" and then "THAT" gets compared with the rest of the elements in the list. This works out only because "THAT" shows up in the later list of items. The second scenario doesn’t work because the items aren’t in the right order.

What you actually want with List.Contains is to reverse the inputs. Both items exist in the list so you would only get two values back if you check the items. Checking to see whether (each item in) the list exists within your list of items returns a value for each item in the larger list - the one you want to filter.

1 Like

Oh wow. This is great. New wrinkles in the ol’ brain. I love the 4 scenarios you presented. Sheds some light on things.

I tried several list levels with list.contains. Nothing worked. Now I see I needed to flip the inputs. Brilliant.

I only flatten the list AFTER the comparison so that I can pass a flat list of booleans to the filter. string.contains using list levels nested the list in another list, so I needed to flatten the output.

Thanks so much!

1 Like

This is exactly why you don’t want to flatten the lists. String.Contains checks a list of strings against a single substring. The two sublists you get represent the checks for each individual substring. That means you want to filter your list of parameters by both lists of booleans - one for the first substring and one for the second. You would flatten the parameters after they’re filtered to maintain a single list of parameters.

1 Like

I hear what you’re saying, but that’s not how my list levels are set up. I used @L2 on the searched list and @L1 on the other. So, per my understanding, it looks at each item in the long list and compares it to each item in the short list before moving on to the next item in the long list. So, the final list is still the same length as the long list.

I don’t get two full 279-item lists inside another list. I have one list inside another list. See my second image I posted where it works with string.contains. I still have one list that is the same length (279) as all the other lists. I just had to get it out of the nesting with flatten.

Have you confirmed it’s working as expected though? I think you’re running into a similar issue as the longest lacing. Using @L2 and @L1 forces paired inputs. You’re saying “use the list at the L2 level with the same indexed value at the L1 level.” Your input list is already an @L2 list which means you have one item @L2 for one input and two items @L1 for the other input. These are mismatched lengths so the node only executes the first pair. If you look at my example, the first list ("A".."Z") looks for item "G" but there’s nothing looking for item "B" because there’s no input list to compare to.


I can’t say why you’re getting two parameters back unless you have two with the same name. Even if it is working for you in this case, it’s bad practice and will likely cause issues ore often than not.

Well, crap. It’s working after several tests. Works exactly as expected. I have no idea why! I thought it might be because of the order of G and B in your test, so I flipped them and it doesn’t work. But my actual script is working. You can see that 261 and 268 in the long list are DISCIPLINE and DISCIPLINE ORDER. And the true values show up at 261 and 268. I don’t get it!


I’m going to switch it to what you suggested, but I’d love to know why what I have is working. It’s weird!

Because “DISCIPLINE ORDER” contains “DISCIPLINE”. :man_facepalming:
Can’t believe I missed that lol. String.Contains checks for a substring match, not a complete match. That’s why the order matters for you.

1 Like

HAHAHAHA! Well, there ya go! LOL! Mystery solved. Okay. I have switched to the list.contains option with your scenario 4. Works like a charm. Thanks, @Nick_Boyts ! You da man! :slight_smile:

1 Like