Combine sublists into a single list

I am trying to combine multiple sublists into a single list. The screenshot shows the output, but the list I would like to get should look like this:
[0] 1
[1] 1
[2] 2
[3] 3
[4] 3
[5] 3
[6] 2
[7] 1


image

A single list will all of the values compacted so there are no empty values. I simply can’t find the right method to achieve this. Has anyone tried to do this before?

List.Flatten and the filter by bool mask where the test is val!=“”;

hi @davidfink67241

try this: list_combine.dyn (5.2 KB)

python code:

out = list()

for i in IN[0]:
	if i is not None:
		try:
			if str(i) != "":
				out.append(i)
		except:
			pass
OUT = out

-biboy

I tried the flattening and filtering the list, but it does not maintain the order of the list. The python script doesn’t seem to work. The list structure remain the the same.

Hi @davidfink67241, can you please explain this:

it does not maintain the order of the list.

What is exactly the output you are looking for?

The python script doesn’t seem to work

You need to flatten first.

I tried this. I am not 100% sure if empty value means always "".

flatten it before passing in the python code:

-biboy

I am trying to flatten the sub-lists into each other. This is different than flattening the lists into a single list and then removing the empty indexes.
There are sublists each with values and empty indexes. The empty indexes need to be removed and the placement of the numbers needs to be maintained. so they can be written back into family parameters.

Here an illustration.

hi @davidfink67241

Now I get what you are trying to do. Check this script: list_combine.dyn (6.8 KB)

look at the python code at the bottom of this pic:

-biboy

The Python script did the trick. I definitely need to improve my Python skills. Thanks for taking the time to help out!

@davidfink67241

no problem, dont forget to mark my answer as the solution :wink: