Finding if the sublists contain a list item in any of the items of the sublists

Hello,

I am trying to know if any item of sublists contain a specific item list, so the results is a True or False for each sublist. for example:
IN[0]=[1,2,3],[4,5,6],[7,8,9]
IN[1]=[1]
OUT=[True,False,False]

In designscript I use the nodes String.Contains and AllFalse to filter but I am trying to do the same with python but I got this so far, it works with simple list but not sublists:

import clr

def ListMatch(ls1, ls2):
	len1 = len(ls1)
	len2 = len(ls2)
	if len1 != len2:
		return False
		
	for i in range(len1):
		if ls1[i] != ls2[i]:
			return False
	
	return True


# Inputs
masterList = IN[0]
searchList = IN[1]

answer = False

for i in range(len(masterList)):
	if ListMatch(masterList[i], searchList):
		answer = True
		break

OUT = answer

@ruben.romero , hi

i did it with this structure:


what are you trying?

for example same list of numbers in[0] and a single item on in[1] for example=[1], if the item in[1] is contained in any of the sublists, give me true, if not, give me false, so in this example the output would be 3 items (true,false,false) because 3 sublists on in[0]

IN[0]=[1,2,3],[4,5,6],[7,8,9]
IN[1]=[1]
OUT=[True,False,False]

lists = IN[0]
target = IN[1]

OUT = [ target in lst for lst in lists ]

I got Empty list after try this, so something does not work

Screenshot the DYN and input data please. Hard to see where things connect otherwise. :slight_smile:

try to put an empty list at beggining of input list to see what happens

Works totally fine on my end; Please post the code and screenshot as requested before.

I have been trying something like that but I get warning index out of range

xFalse= tolist(False)
xTrue= tolist(True)
boolero = []

for i in range(len(boolslicedgroup)):
    if(boolslicedgroup[i]) :
        boolero.append(xFalse[i])
    else:
        boolero.append(xTrue[i])

I achieved it like this but it seems a nightmare again for something simple

xxxx=["comments"]
xTrue = True

def ListContains(item, filter):
	bool = False
	for i in filter:
		if i in item:
			return True
			bool = True
	if not bool:
		return False 

def ProcessListArg(_func, _list, _arg):
	return map( lambda x: ProcessListArg(_func, x, _arg) if type(x)==list else _func(x, _arg), _list )

boolslicedgroup = ProcessListArg(ListContains, sliced, xxxx)
boolsublist = [ xTrue in booleans for booleans in boolslicedgroup ]

That is a bit of a mess, however I’m lost as to what data you have which is causing the issue. If you post the previously requested screenshot of the data structure I can try to help simplify, but short of that you’ll have to run with what you’ve got.