length
How many distinct items are in this set? Just count them
- set
- length
length takes a SET and returns how many elements it contains as an INT. That's the whole node - Python's len() exposed in the graph. Simple enough to look pointless, until you realize that "how many unique things do I have" is a question you'll ask constantly once you're building conditional workflows.
It's the workhorse of the SET category because every other node in it produces a set whose usefulness you often want to quantify. Feed a union or intersection result into length to count what you ended up with. Use it to branch a workflow on "is this pool empty or non-empty" via a comparison node - length == 0 is your "nothing matched" signal, which is exactly the edge case that intersection or difference will silently hand you. Pair it with contains when you need both "is it there" and "how much is there."
How it works
The mechanism is len(set) - O(1), instant, no iteration. A set already tracks its own size, so this is a pure read that costs effectively nothing in the graph. It emits an INT you can wire into any numeric input, arithmetic node, or comparison in the pack.
The one conceptual point to internalize: this counts distinct values, because that's what a set holds. If you built the set from a list with duplicates, length reports the post-dedupe size, not the original count. If you need the raw count with duplicates, don't use a set at all - use a LIST and this pack's count node in the LIST category.
Inputs and output
set(SET) - the set to measure.length(INT, output) - the number of elements.
One required input, one integer out. Nothing else to configure, and the output name length matches the display name so you won't lose it in the graph.
Installing
It's part of Basic data handling by StableLlama. Fastest via ComfyUI Manager - search "Basic data handling", install, restart. Or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart ComfyUI after cloning. Zero dependencies, no models - this is one of those packs that installs clean in seconds and can't conflict with the heavy sampler/upscaler packs in your environment.
Common issues
The only real surprise is the dedupe thing above: length is a count of unique values, and if you were expecting the number of items you fed in, you'll be short. If you're troubleshooting a set that seems too small, that's usually intentional deduplication doing its job - check what you put in with contains. And remember an empty set legitimately returns 0, which makes length == 0 your cleanest "set is empty" branch.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| set | SET | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| length | INT | — |