Creating one list from sub-lists based on whether it contains at least one "true"


#1

Hi Everyone,

I have a simple issue that I simply cannot get right.

I have a list of 10 sublists, each containing 2 boolean values, as you can see at the right of the screenshot. What I need to do is create one list, of 10 boolean items from that list.

If there is at least one true in the first sublist, I need it to give me a value of true in the second final list. If they are both false, I need a false.

Any help would be greatly appreciated. I’ve tried a dozen different list nodes, in different combinations, and I just can’t get it to work!


#2

Try this in a python script node:

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
input = IN[0]

outList = []

for list in input:
----if True in list:
--------outList.Add(True)
----else:
--------outList.Add(False)
OUT = outList


#3

I could not put the correct identation here so just change ---- for a “Tab”


#4

#5

ricardoperucci,

thank you for your response. I tried the Python code you show, and, when written letter for letter, the python node gives me an error.

I did, however, just a couple minutes ago, get the correct result just by the “list.ContainsItem” node.

Is there an advantage using the Python script as opposed to that? or are there downsides to achieving this with that simple node?

Thanks again


#6

None :slight_smile:

However, you can avoid using List.Map by changing lacing to Longest
20171130-2


#7

You need to link your “true/false” list of lists on the python node… You could just do it as Vikram_Subbaiah said, nothing different!


#8

Thank you very much!