Null to Empty to Variable

It didn’t work because you have a list with sub-lists, which means that you have to add another loop to iterate the sub-lists as well. So this would be something like:

def item_tolist (input):
	tolist = input if isinstance(input,list) else [input]
	return tolist

var = item_tolist(IN[0])
string = IN[1]

result = []
first_lp_list = []

for lst in var:
	if lst == []:
		first_lp_list.append(string)
		result.append(first_lp_list)
	else:
		sec_lp_list = []
		for item in lst:
			if item==[]:
				sec_lp_list.append(string)
			else:
				sec_lp_list.append(item)
		result.append(sec_lp_list)
	
OUT = result

You can also check @AmolShah solution for a similar case.

2 Likes