Merge 2 lists while setting sublists from bool

Is there a way to merge list 1 and list 2 while ‘replacing’* the values from the bool true = list 1 and false = list 2 and keeping all the sublists from the bool?
*not actually replacing since these are other elements, but somehow putting in the same place as the bool list.

Hello @Laura_BIMChick
a solution with Python

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

boolLst = IN[0]
iterTrue = iter(IN[1])
iterFalse = iter(IN[2])


OUT = [[next(iterTrue) if val else next(iterFalse) for val in sublst] for sublst in boolLst]
3 Likes


booleanMerge.dyn (23.2 KB)

3 Likes

@c.poupin Thanks, the python works great!

@Vikram_Subbaiah Thanks for this solution with nodes, I’ll try it out later next week.
For now the python works great for me.

1 Like

@Vikram_Subbaiah Would you have a similar solution for this?
Every true value needs to be replaced by a surface, but I need to keep the empty lists.
All false values need to be null values.
I’ve been trying to reconfigure your solution but I can’t get it to work…

Not similar, but work for you. Cant think of a simple solution right now :neutral_face:

t = true;
f = false;
a = [[t,t],[t,f],[],[],[t],[t,t,f],[],[t,f]];
b = "Surface " + (1..7);
h = [Imperative]
{
	c = 0;
	d = [];
	g = 0;
	for (i in a)
	{
		e = List.Count(i);
		f = 0;
		if (e != 0)
		{

			for (j in i)
			{
				if (j)
				{
					d[c][f] = b[g];
					g = g + 1;
					f = f + 1;
				}
				else
				{
					d[c][f] = null;
					f = f + 1;
				}
			}
			c = c + 1;
		}
		else
		{
			d[c] = [];
			c = c + 1;
		}
	}
	return d;
};

A solution with nodes


replaceTrue.dyn (28.1 KB)

ls1 = List.Flatten(lst1,-1);
ls2 = List.GroupByKey(0..(List.Count(ls1)-1),ls1);
ls3 = List.SortByKey(ls2["groups"],ls2["unique keys"])["sortedList"];
ls4 = [List.OfRepeatedItem(null,List.CountFalse(ls1)),lst2];
ls5 = List.SortByKey(List.Flatten(ls4,-1),List.Flatten(ls3,-1));
ls6 = List.Chop(ls5["sortedList"],List.Count(lst1<1>));
1 Like

Thankssss!

1 Like