@@ -295,6 +295,46 @@ def filter_data(self, **kwargs: list[Any]) -> tuple[list[Any]]:
295295 return (result ,)
296296
297297
298+ class DataListFilterSelect (ComfyNodeABC ):
299+ """
300+ Filters a Data List using boolean values.
301+
302+ This node takes a value Data List and a filter Data List (containing only boolean values).
303+ It returns two new Data Lists containing only the elements from the value list where the
304+ corresponding element in the filter list is true or false.
305+
306+ If the lists have different lengths, the last element of the shorter list is repeated
307+ till the lengths are matching.
308+ """
309+ @classmethod
310+ def INPUT_TYPES (cls ):
311+ return {
312+ "required" : {
313+ "value" : (IO .ANY , {}),
314+ "select" : (IO .BOOLEAN , {}),
315+ }
316+ }
317+
318+ RETURN_TYPES = (IO .ANY , IO .ANY )
319+ RETURN_NAMES = ("true" , "false" )
320+ CATEGORY = "Basic/Data List"
321+ DESCRIPTION = cleandoc (__doc__ or "" )
322+ FUNCTION = "select"
323+ INPUT_IS_LIST = True
324+ OUTPUT_IS_LIST = (True , True ,)
325+
326+ def select (self , ** kwargs : list [Any ]) -> tuple [list [Any ]]:
327+ values = kwargs .get ('value' , [])
328+ selects = kwargs .get ('select' , [])
329+
330+ # Create a new list with only items where the filter is False
331+ result_true , result_false = [], []
332+ for value , select in zip (values , selects ):
333+ (result_true if select else result_false ).append (value )
334+
335+ return result_true , result_false
336+
337+
298338class DataListGetItem (ComfyNodeABC ):
299339 """
300340 Retrieves an item at a specified position in a list.
@@ -771,7 +811,7 @@ def INPUT_TYPES(cls):
771811 INPUT_IS_LIST = True
772812
773813 def convert (self , ** kwargs : list [Any ]) -> tuple [list [Any ]]:
774- return (kwargs .get ('list' , []).copy (),)
814+ return (list ( kwargs .get ('list' , []) ).copy (),)
775815
776816
777817class DataListToSet (ComfyNodeABC ):
@@ -810,6 +850,7 @@ def convert(self, **kwargs: list[Any]) -> tuple[set[Any]]:
810850 "Basic data handling: DataListCount" : DataListCount ,
811851 "Basic data handling: DataListExtend" : DataListExtend ,
812852 "Basic data handling: DataListFilter" : DataListFilter ,
853+ "Basic data handling: DataListFilterSelect" : DataListFilterSelect ,
813854 "Basic data handling: DataListGetItem" : DataListGetItem ,
814855 "Basic data handling: DataListIndex" : DataListIndex ,
815856 "Basic data handling: DataListInsert" : DataListInsert ,
@@ -838,6 +879,7 @@ def convert(self, **kwargs: list[Any]) -> tuple[set[Any]]:
838879 "Basic data handling: DataListCount" : "count" ,
839880 "Basic data handling: DataListExtend" : "extend" ,
840881 "Basic data handling: DataListFilter" : "filter" ,
882+ "Basic data handling: DataListFilterSelect" : "filter select" ,
841883 "Basic data handling: DataListGetItem" : "get item" ,
842884 "Basic data handling: DataListIndex" : "index" ,
843885 "Basic data handling: DataListInsert" : "insert" ,
0 commit comments