Replace non boolean


Hi all,I’ve been trying to convert the true values of a list by a numeric values from other list and remove the false values also. I’ve been using design script which was posted long back. But it is not working. Where I did wrong? or any other solution.

Ilayaraja P


It’s doin exactly as expected, Applying the numeric list to each boolean sub-lists. I’m going to assume your only problem is with the null values. Otherwise, it’s about lacing.

Unless you can modify the design script, I suggest you use nodes. It does make things longer but it’s sometime crucial for the sake of clarity and reusability.

Go for a filter by bool mask and a remove null( lunchbox ) to acheive the same goal. Or just plug a remove null after your graph.


Thanks @slepagetrudeau for your reply
For Example I have 20 nos of true and 20 nos of numeric value. I just want to replace the true with numeric value. In your example its repeating the numeric value ( 2 & 3) base on the sub list number. Also I dont want to remove null and this null will be replaced by black sub list later. I hope you got my point.



Are the sub lists important? Could you flatten the whole thing?


Your list structure certainly doesn’t match. You have 23 numbers and 68 booleans (and it doesn’t even look like 23 lists of booleans).

What is your overall goal? What are you checking the numbers for?
A better explanation of your process will allow us to give a better solution.


hi @pilayaa
I am not sure if this helps you, but as I see your first graph, then I would expect something like this… but @Nick_Boyts has a point, is your list in the right length?


Thank you all for your reply.
@slepagetrudeau, Yes the sub lists are important. This is for part of the electrical Distribution schedule. I will replace the null with black value later.
@Nick_Boyts, I have 68 booleans. In that I have ‘23’ number of true and ‘23’ number of numeric values. I just want to replace the true with numeric values.
@erfajo your solution works until we have one true in the sub list. If we have more than one ‘true’ it will repeat the numeric value. See the below snap for more clarity.

Ilayaraja P


Thanks for clarifying. This also answers @Nick_Boyts question. So your lists contain 23 true values scattered in list ‘a’ sublist (the 68 booleans) somewhere. It is those ”truths” your need to replace by number values while keeping the list structure from list a.


@erfajo, You are right.


Is the sublist always 4 items deep?


try this

lst = IN[0]
num = IN[1]

t2 = []
for sub_lst in lst:
    t1 = []
    for item in sub_lst:
        if item:

OUT = t2


Thanks @erfajo for your time and suggestion.
I replicate the same what you did. But its not work for me. What did I wrong?


I assume you get an error according to indentions.
python is sensitive towards indentions…

In general, uploading your .dyn files when you need help will help all those who might be able to help you.
I admit that I only help those who include their effort so far attaching the needed files. I don’t have the time to replicate other users graphs or working files. Yours was very simple so that’s why I helped.

here is my .dyn file
Home.dyn (4.6 KB)


I don’t have an idea about python script. That’s why I couldn’t find the error. Thanks for your help and .dyn file. I will check and let you know .


Hi @erfajo
It works now. Once again thanks for your help.


you are welcome :thumbsup: