Search string items of ListB in ListA ( resembling items )

Hi,
It seems like a simple job but I am stuck with this task.
I have to find string items of ListA in ListB. However, with a condition that I dont have to write exact same string, meaning, that the funtion retrieves values closest to the string that I demanded.

Ideally, String.Contains should work, i tried to adjust NodeLevels, no luck so far.

Reason being LevelNames are long strings and chances of mistake is higher for other users.

ps. I like to add some context: I am trying the replicate the method from this tutorial, so I can create sheets directly from Levels. In reality, projects dont have just 2 levels for each floor: Each floor has around 4-5 levels, hence I need a selection toggle, or just type the levels I need. The project I am working has around 50 levels and its hard to even search through a drop down menu. Typing seems like the best option.
Auto-Documentation With Dynamo! Part 1 - Create Views, Sheets, and Drop Views on Sheets - YouTube

hi
use String Contains with cross product lacing, then use anytrue node @L2

Thanks, lacing totally slipped my mind.
However, the method worked partially, not exactly what I intended. I want to search listA strings that contains all the alphabets of listB string.

There are lot of items in listA that contains letters ‘eg’, but only one item that contains ‘eg ffb’.
Is there a way to search string like that ? or

There is only one item that contains letters ‘1 og ffb’.

Hi Guys
Can’t find it because it’s looking for “og ffb”.
When I did “og” it worked properly.

1 Like

yes, I am having the same problem :slight_smile:
I was thinking if anyone expert in CodeBlocks can tell us, if there is a way to split string and search,
something like … instead of searching ‘eg ffb’, we could search ‘eg+ffb’. so it searches ‘eg’, and then eg with ‘ffb’ ?

split is what you need

image

so I asked a friend, he guided me to a python logic.

I am still struggling to get the desired result.


So, using same script, i can filter all elements that has ‘EG’ and ‘OG’ in name, but I want to further filter down to item that has ‘EG FFB’. How would that work ?

You can only check a single continuous substring at a time without getting into RegEx. “This That” is not the same as “This” and “That”. What you’re really asking is to search for two substrings at the same time, so that’s what you have to do.

Python
listA = IN[0]
listB = IN[1]
out = []

for a in listA:
    for b in listB:
        allPass = 0
        for sub in b:
            if sub in a:
                allPass += 1
        if allPass == len(b):
            out.append(a)

OUT = out

Thank you Nick for detailed solution. Python and Dynamo both.

I copied your script and it didnt give me results I intended. I would like to add here that I am a beginner at python, so I wasnt able to edit your script. I like to understand the logic behind ‘allPass’ though, I checked some python tutorials about ‘allPass’ they were talking about wave funtions and complex equations.

Secondly, a non-AEC friend:) asked me to use get_close_match funtion. It makes more sense as it is simpler to understand. I am posting both scripts here for experts to see if it’s the right way to go. So far I am getting the results I wanted. Just have one more look before I mark this post as resolved.

PS. In cutoff value, I was wonderig if it is possible in DynamoPython to use ‘greater than or equal to’ ?
I tried using >= but it didnt work. Just curious !

Using close_matches is a great solution but might be somewhat inconsistent depending on how varied your strings are. Just keep that in mind.

As for the example I gave, you’re still using single substrings. As I’ve already mentioned, that will not work with searching. If you look at my graph you’ll see I split each “search” value into a list of substrings so that the code can check for each one individually.

The allPass I’m using is just a variable to make sure that all substrings within a search value are found within a string in order to be accepted.