Replace empty list with list (eg. replace empty list with [A,B,C] )

Hello all, I’m trying to replace the empty lists with list

eg.

index 1 [a,b,c]
index 2 [a,b,c]
index 3 empty list
index 4 [a,b,c]
index 5 empty list

-I want to replace the empty list with a list [A,B,C]

index 1 [a,b,c]
index 2 [a,b,c]
index 3 [A,B,C]
index 4 [a,b,c]
index 5 [A,B,C]

I’ve tested several methods but none of them work perfectly. Some of them work with a single value, some of them can only replace item at one index. Please see the snapshot for detail.

I really hope someone can give me some advice. Thank you!

Make the List.ReplaceEmptyList cross-laced

1 Like

I believe Orchid has nodes for replacing multiple indices in a list or you can write something in python to do it. Ootb nodes won’t do multiple indices at once.

1 Like

Thanks, Daan & Nick

I manage to use both List.ReplaceEmptyLists and Manage.ReplaceNulls to get what I want.

Here is the solution:

1 Like

@Macchi I don’t think that worked as you expected. Look at the values of your sublists. They’re just being repeated.

Here’s a simple python code that will do the trick:

output = []

for a in IN[0]:
	if len(a) == 0:
		output.append(IN[1])
	else:
		output.append(a)
		
OUT = output

8 Likes

Thanks Nick. That’s a much simpler solution.

1 Like

HI Nick_Boyts

I could not use this python code for the below case. Please advise.

@Ravindra.Karale Hi and welcome, it works perfectly from my side, can you show the Python code?

Hi Elie.Trad, Many thanks for your reply. An attached snip for your review.

You have an extra list level. You either need to remove it or modify the code to handle that extra layer with another loop.

Many thanks Nick!