Hi there,
I have job need to combine multi-lists to one shown as attached files. I need to combine these three lists on the left side to one list on the right side. I need to keep the value of null on the right list as well if there are not any value exists on the position of left side lists.
Thanks
List Forming.dyn (41.1 KB)
@Seanc9XFAH Try this:
OUT = [None if not any(x) else filter(None, x)[0] for x in map(list, zip(*IN))]
2 Likes
@Seanc9XFAH You can also do something like this using OOTB nodes:
Option-1
Option-2
1 Like
Python in that
Bakery node is:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
withnulls = IN[0]
originals = IN[1]
newlist = []
for x in range(len(withnulls)):
if withnulls[x]:
newlist.append(withnulls[x])
else:
newlist.append(originals[x])
#Assign your output to the OUT variable.
OUT = newlist
1 Like
Hi @AmolShah
It seen we are almost there! your scripts works perfectly solved partially of my problem. The rest of part is almost same with the current one, but the only difference is there are two lists under one list. I tried to adjust around levels and keep list structures. However it seems no luck. Could you please help me to adjust it bit.
List Forming2.dyn (127.5 KB)
@Seanc9XFAH Here you go: List Forming2.dyn (139.4 KB)
OUT = [None if not any(x) else filter(None, x)[0] for x in map(list, zip(*IN[0]))]
Hi @AmolShah,
Thanks for doing this. This works only in this example as it only have two sub-lists under each list for easier to explain the situation.
The reality is that I got more than that lists and way more than two sub-lists on each, could you please provide any another options?
Thanks again.
Hi @truevis ,
Thanks for help. could you please let me know how do i get the script of “Replace Nulls with Other List Pythonic”? I cannot find it from my Dynamo. I tried to copy the scrpits that you have attached and paste it into python script, but it doesn’t work.
Additionally, @AmolShah’s scripts helped figured out the example problem, However, there is another problem is almost same with the example, but the only difference is there are two sub-lists under each list. I think it supposed be solved by adjusting levels and keep list structure sort of thing. I am still trying the adjustment at the moment. could you please help me to have look it. I have attached the dyn file here for you.
PS. It only shows two sub-lists under each list in example is for easier to demonstrate. In the real case, I have got way more sub-lists and way more lists.
Thank you again
List Forming2.dyn (127.5 KB)
@Seanc9XFAH Give this a try: List Forming2.dyn (131.9 KB)
OUT = [[None if not any(x) else filter(None, x)[0] for x in map(list, zip(*y))] for y in map(list, zip(*IN))]
IF YOU NEED MORE HELP, PLEASE SHARE YOUR ENTIRE DYNAMO GRAPH AND A SAMPLE REVIT FILE FOR THE PROBLEM YOU ARE TRYING TO SOLVE.
2 Likes
Hi @AmolShah ,
Appreciate sooooooo much. This scripts works very well. You perfectly solved my all problems.
Appreciate again ^v^
1 Like