symmetric difference
Everything in either, nothing in both
- set1
- set2
- SET
symmetric difference returns the elements that are in either of two sets but not in both. If you know the logic term, it's the XOR of sets - the union minus the intersection. If you don't, think "what's unique to each side?"
That "unique to each side" framing is what makes it genuinely useful rather than a math curio. Say you have a "tags I want" set and a "tags I've already used" set. Symmetric difference gives you the tags that are in one list but not the other - everything new, nothing repeated. Or diff two sets of generated frames to find which ones appeared in exactly one batch. It's the complement of intersection (shared elements) and the "either but not both" middle ground between union (everything) and difference (only in the first).
How it works
The mechanism is Python's symmetric_difference_update: the node copies set1, then for every element of set2 either adds it (if it's not in the copy) or removes it (if it is). Net effect - elements in exactly one of the two sets.
Two properties to hold onto:
- It's symmetric. Unlike difference, swapping the inputs gives the same result. No direction to get backwards.
- Non-destructive.
set1is copied, so your original sets survive for use elsewhere in the graph.
Inputs and output
set1(SET) - first set.set2(SET) - second set.- SET (output) - elements present in exactly one of the two inputs.
Just two required inputs and a single SET out. If you need the "unique to A only" or "unique to B only" sides separately, that's what the plain difference node is for, run in each direction.
Installing
It's in Basic data handling by StableLlama. ComfyUI Manager is the easy route - search "Basic data handling", install, restart. Or clone:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart ComfyUI after installing. Zero dependencies, no model downloads - pure Python, so it installs clean and fast.
Common issues
The one mental trap is confusing it with difference. Difference is "only in set1" - directional, asymmetric. Symmetric difference is "in exactly one of them" - bidirectional. If you were expecting one-sided output and got both sides, you grabbed the wrong node. And as always with sets, membership is exact: "new" vs "New" won't be recognized as the same element, so they'll both show up in the result.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| set1 | SET | — | |
| set2 | SET | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| SET | SET | — |