Dictionary finding a part of a value key

Hello,

I am struggling with something that in theory seems very simple, but I am not able to make it work :roll_eyes:


I have a dictionary, which has room names as keys. I want to find in this dictionary the equivalent families (values) for these rooms, but only by inserting part of their names.

Would anyone know how to do this?
Grateful to all ideas

this concept could help

2 Likes

Thanks for the reply @khuzaimah.ElecEng . But I can’t solve my problem that way … because I need to relate a list of strings with parts of the name, not just one string

for the list try this if i understand your issue right

Basically what Khuzaimah did but with python:

dataEnteringNode = IN
keys = IN[0]
values = IN[1]
searches = IN[2]
out = []

for search in searches:
	for key,value in zip(keys,values):
		if key in search:
			out.append(value)

OUT = out

Also a dictionary probably isn’t necessary if you don’t match the keys anyway. A filter would work just as well:

Thank you so much guys … but I ended up having to solve it in another way and not using contain. Partly because:

  1. some pieces of words were in more than one key;
  2. Partly because I often had name parts that were like “CAS MAQ” which are the first 3 letters of each word in “CASA MAQUINAS” … so it didn’t match…
    But I appreciate the assistance, maybe this solution will be useful for a next routine!