Wall's materials: removing null and empty list but not change the list's values order

Hello everybody!
Here is a little exercise I’m doing: trying to extract materials from wall types and to have an organized list of them for each type.
Though there are empty list and null element in my list of materials. How can I get rid of these elements?
When I get rid of them, I also need to keep correspondence with the wall in Revit

Thank you in advance!!
Hope you can help me

Check this.

Thank you!
It still has some problems apparently with the string

do you have any idea?

Use String from Object after List.Flatten and numbers instead of elements to index of List.GetItemAtIndex.

Thank you, but I’m not sure it works… the problem is that now I have a random list of values that correspond to specific elements. The list of elements are family types (and it’s a list of 133 items); this random list is composed by 115 items that should be placed at their right place…

I’ll try to be more clear,
These 115 elements correspond to specific elements in a list composed by 133 elements that has been cleaned from null and empty elements. How can I recreate the correspondance in the right way after cleaning the list?

remove the nulls and empty’s first
you could try this

you want 133 items in List.Flatten?

Actually the problem is that, after removing null and empty lists, the list is shorter than before, but I need not to loose the equal number of items in the two lists, in order to keep in both the lists the same order.

is working with dictionaries using a unique key (like the revit GUID) instead of ordered list an option? that´s usually a more robust approach in my opinion

If you want to keep the same number of sublists you can’t remove the empty lists. You would either have to keep them as placeholders or replace them with another list (maybe with blank values or something). You should be able to use Flatten with list levels (although I haven’t been able to tell if that’s even necessary), CleanList to remove nulls, then do whatever you want to do to the remaining empty lists.

If the two list are of equal length and are referring to the same elements you can feed this list in the filter by boolmask.

Thanks everybody!
I solved it! as you said, I shouldn’t remove the null elements, but just need to replace them!
:v:
everyone was very helpful, as always, thank you!!