Python. If sublist items are all false make them true, if not leave it as is it

Hello,

what I pretend to get is: if I get a sublist that contains all False, then convert all items of that sublist in True, if there is any true in the sublist then leave the sublist as it is.

Input list=[[false,false,false],[false,true,false],[Empty list]]

Desired output=[ [true,true,true] ,[false,true,false],[Empty List]]

I resolved it with OOTB nodes like that but I wish to achieve it with Python code

@ruben.romero You can do something like this:

toList = lambda x : x if hasattr(x, '__iter__') else [x]
OUT = [x if any(x) else [True]*len(x) for x in toList(IN[0])]
2 Likes

it works great you are star

1 Like