Searching strings in python while maintaining data tree structure

Hi all, many apologies if this is a stupid question.

In short, if you are familiar with it, I am wondering how to re-create the SonicStringSearch from the plug-in Mosquito using Python. It feels like it shouldn’t be complicated, but on top of not being very good at Python, I don’t really understand how to relate lists in Python to data trees in grasshopper.

If you’re not familiar with it, then it is a component that allows you to run through a list of strings and perform a sub-string search on it (with a toggle for case sensitivity). The output is a cull pattern with the expected data-tree structure.

I apologise for the fact that I don’t even have a basic script for you to look over but it’s because my attempts were so far wrong that it didn’t seem meaningful to include any of them.

See attached. It’s not P (I don’t like that thing at all) but the approach should be rather clear - I do hope. (118.9 KB)

In Python, if you are looking for a cull pattern output, maybe you could just try:

a = "your sub-string" in x