List-replace Multi Elements

list-filter
#1

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)

0 Likes

#3

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

#4

Thank you,

Thats nice, works awesome

0 Likes

#5

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];
0 Likes

#6

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

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

0 Likes

#7

You need to tweak the python script a bit, but the designscript from @adam_bear1 works out of the box!

String_Replace_listElements.dyn (6.1 KB)

1 Like

Python Nodes Basics
#8

@Heinrich_Boldt with OOTB nodes …

4 Likes

#9

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