add
Add an item to a SET without mutating the original
- set
- item
- SET
Sets are the "only unique values" collection - no duplicates, ever - and add is how you put a new member in. You feed it a SET and an item, and it returns a fresh SET with that item included. If the item's already in there, nothing changes, which is the whole point of the type: adding "cat" to {"cat", "dog"} is a no-op, and that's the desired behavior, not a bug.
Why would you want this in ComfyUI? The classic use is accumulating a growing set across a workflow - a running allow-list of tags, a collection of seeds you've already processed, a deduplicated set of captions - then checking membership later with the pack's contains, or testing emptiness with all/any. Because this pack implements SET as a Python set passed as a single variable, you get real set semantics (fast membership, dedup) rather than approximating them with lists.
How it works
set.copy() then .add(item) - the copy is deliberate. ComfyUI nodes should be pure: each execution hands you a new SET and leaves the input untouched, so the same SET can feed multiple add/remove branches without cross-contamination. The item slot is * (any type), which is both flexible and a footgun: sets deduplicate by hash, so 1 and True are the same member, and two dicts are distinct even if their contents are identical. Strings, numbers, booleans - all behave as you'd expect; keep the input type consistent and this never bites you.
Inputs and output
set- the SET to add to.item- the value to add (any type).
Output is the new SET, including the item.
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 downloads - the pack's whole pitch is that it's stdlib-only and install-safe.
Gotchas
- The no-op-on-duplicate behavior is the feature, but it means "did the add do anything?" is only answerable by checking the SET's length before and after.
- Mixed types dedup weirdly:
1andTruecollide, and unhashable items (a raw LIST, for instance) will fail when the SET tries to store them. Feed it scalars and strings and you're fine. - It returns a new SET; it doesn't update in place. If you're chaining adds, wire each node's output into the next.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| set | SET | — | |
| item | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| SET | SET | — |