Matching partial string in 2 lists and passing both strings forward

I have 2 lists. 1 is a list of elements service names, and the second is a list of materials.
I would like to match the elements service name that contains the material name(shorter string). then pass the element and the material name so I can assign the correct material to the element. I have been using string.contains and list.filterbyboolmask. However I cannot get a list of materials matched to elements.

@pipefitter72 Not sure how accurate this would be. But try look into fuzzy string matching.

There is a package called FuzzyDyno to get started with. But I don’t prefer that since it always freezes on me.

Alternatively, you can download the fuzzywuzzy python package and do something like this:

1 Like

That looks like what I need. However after installing fuzzywuzzy from github. I must not be doing something right. I keep getting the following error.

@pipefitter72 Try this:

  1. Download the package by clicking on this link: https://github.com/seatgeek/fuzzywuzzy/archive/refs/heads/master.zip

  2. Open the downloaded zip file and extract the fuzzywuzzy folder on your desktop
    image

  3. Change your code as below and replace YOURUSERNAME with your windows username
    image


import sys
sys.path.append(r'C:\Users\YOURUSERNAME\Desktop')

from fuzzywuzzy import process
OUT=[]
for x in IN[0]:
	OUT.append(process.extractOne(x,IN[1])[0])

LOL I was coming to post that I figured what I was doing wrong. But I see you beat me to it.
I have it working now, but not giving the result I need exactly. I will see what I can do with it. Thanks.

1 Like

I think you were on the right track in your OP.

1 Like

I keep trying that setup, but I have begun to think the service names are too long to be handled. some of them are 30+ characters long

You do have a list transpose after the contains node. Have you removed that?

I have tried with and without

Got it working, I just had to do some list flattening, and I adjusted some of the material names. Thanks for all the help. I appreciate you guys taking time to look over this for me.