List-replace Multi Elements

Hi,

i try to replace multi Elements in a List with different “Replacements”

But the Node “List.Replace” replace not all Elements.
Where is my problem?
String_Replace_listElements.dyn (3.6 KB)

try this:

OUT=[]

for i in IN[0]:
	for c in range(len(IN[1])):
		if i==IN[1][c]:
			OUT.append(IN[2][c])

1 Like

Thank you,

Thats nice, works awesome

or you can use design script dictionary key values
see this post

keys 			= 	{"5426", "5421", "5422"};
values 			= 	{ "MW",   "STB", "BFT" };

inputs			= 	{
					"5426","5421","5422",
					"5421","5422","5426",
					"5422","5421","5422",
					"5426"
					};

//	define values at key index
	dic[keys]	= values;

//	read values at input index
	output 		= dic[inputs];

Hi, this Script make a new list, without elements where no matching is.

can i change it?
i Need a List, with all Elements

@Heinrich_Boldt with OOTB nodes …

4 Likes

This will work also if values are not found:

repl=dict(zip(IN[1],IN[2]))
OUT=[repl[i] if i in repl else "Not Found" for i in IN[0]]

“Not Found” can be replaced with anything you want

So if you want the same item back:

repl=dict(zip(IN[1],IN[2]))
OUT=[repl[i] if i in repl else i for i in IN[0]]
2 Likes