ComfyUI Node

contains

The membership test that turns 'is it in the list?' into a boolean

By StableLlama·Created about a year ago·Updated a day ago· 48
contains
  • list
  • value
  • contains

"Is this one of those?" is a question that comes up constantly once workflows get any logic in them - is this seed in my banned list, is this tag already in my set of applied tags, does this filename match any of my exclusions. contains answers it: feed it a data list and a value, get back a single boolean.

It's part of Basic data handling, StableLlama's zero-dependency utility pack, and it's a straight port of Python's in operator.

How it works

Python's value in list, with the list unwrapped from its data-list form. The node takes the value you care about, checks it against every element of list, and returns True on the first match. It's a plain linear membership test, so it's fast enough for anything you'd realistically do inside a workflow.

The inputs and output

  • list (*) - the data list to search.
  • value (*) - the thing you're looking for.
  • contains (BOOLEAN) - True if the value is present, False otherwise.

A realistic use

The output is a perfect condition for an if/else. Say you have a curated list of "good seeds" - check a random seed against the list and route through it only if it's a match, otherwise re-roll. Or use it as a gate: if a tag already appears in your collected list, skip adding it again, which keeps later steps from duplicating work.

Installing it

ComfyUI Manager → search "Basic data handling", or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart. No dependencies, no models.

Common issues

  • "It said not-contains but the value is obviously there." Type mismatch is the usual culprit - 2 (INT) and "2" (STRING) are different values to Python. Cast both sides to the same type before comparing.
  • "I need the position, not just a yes/no." That's the index node in the same pack - it returns where the value lives (or -1 if absent). Contains is only the boolean question.
  • "This is a SET, not a data list." Sets have their own contains node (SET contains) in the SET family - same idea, different type. Don't wire a SET into this one.
CategoryBasic/Data List

Inputs (2)

NameTypeDefaultDescription
list*
value*

Outputs (1)

NameTypeDescription
containsBOOLEAN