ComfyUI Node

contains

Is this value in the set? Membership, answered with a boolean

By StableLlama·Created about a year ago·Updated 4 days ago· 48
contains
  • set
  • value
  • contains

Membership checks are the reason sets exist, and contains is the node that does them: give it a SET and a value, and it returns True if the value is in the set, False if not. It's the fastest, most readable "have I seen this before?" in the whole pack - and because it's a set, that check is O(1), not a linear scan like it would be over a LIST.

The workflow pattern is a running history: collect every seed you've already generated into a SET, and before each new generation, check contains to decide whether to skip or regenerate. Same trick for prompts you've already processed, tags you've already normalized, or any deduplicated catalog you've built with this pack's SET nodes. contains is the read side of that ledger - add writes to it, contains asks it questions.

How it works

value in set - Python's membership test, nothing more. The details that matter:

  • Membership is by equality and hash: "cat" in {"cat"} is True, and so is 1 in {True} (they hash equal). Two dicts with identical contents are not equal as set members.
  • Case matters. "CAT" in {"cat"} is False. If your values are messy, normalize the case on the way in.
  • The value slot is * (any type), and it's compared against whatever's stored, so consistency between what you add and what you check is on you - check for "5" and you won't find 5.

Inputs and output

  • set - the SET to search.
  • value - the thing to look for (any type).

Output is contains, a single BOOLEAN, ready to feed the pack's if/else, all/any, or control-flow nodes.

Installing it

Part of the Basic data handling pack by StableLlama:

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

Restart, or install via ComfyUI Manager (search "Basic data handling"). Zero dependencies, no model files - install can't break anything.

Gotchas

  • It's equality-based, not "close enough." A float 1.0 and an int 1 match; "1" does not. Keep types consistent between the writing and reading sides.
  • Missing value is False, not an error. If you're checking a set that might never have been populated, that's a silent no - check set length first if "did we record anything" is part of the question.
  • Use this instead of any when the question is about a specific value; any only tells you about truthiness.
CategoryBasic/SET

Inputs (2)

NameTypeDefaultDescription
setSET
value*

Outputs (1)

NameTypeDescription
containsBOOLEAN