Flatten sublists with one value

Hi, How do I flatten sublists with only 1 value and leave anything more as part of a sublist.

image

> import clr
> clr.AddReference('ProtoGeometry')
> from Autodesk.DesignScript.Geometry import *
> 
> dataEnteringNode = IN
> 
> x =IN[0]
> o = []
> 
> for i in x:
> 	k = 0
> 	for j in i:
> 		k = k +1
> 	if k < 2:
> 		o.append(j)
> 	
> OUT = o
1 Like

Hi,

Just after your List.SubListLengths node, create a list of booleans that are true if the length of the sublist is 1, false otherwise (you can do this by using the == node, and compare the lengths of the sublists to 1).

Then, just use the List.FilterByBoolMask. The list should be the very first one you have in your screenshot, the booleans should be the list of booleans you just created.

Then apply the Element.CurtainGridLine at the very end of your script.