pop
Grab any element out of a set — and get the rest back too
- set
- set
- item
pop removes an arbitrary element from a set and hands you two things: the new set with that element gone, and the element itself. It's Python's set.pop() as a node - and the word "arbitrary" is doing a lot of work there, because unlike a list's pop, you don't get to choose which item comes out.
The two outputs are the point. Most set operations in this pack hand back one set; pop gives you the element and the updated set, which is the shape you want when you're pulling items out of a pool one at a time. Think of draining a work queue: pop something off, process it, pop again. Because it's non-destructive to the input - you get a new set back - you can keep the original pool intact while also collecting popped elements.
How it works
The mechanism is a copy-and-pop: the node copies the input set, pops an element off the copy, and returns (new_set, item). Which element comes out is determined by Python's internal hash ordering - "arbitrary" is Python's word, and it means "don't make plans around which one." It's consistent for the same set in the same session, but it's not random, and it's not your choice.
Two edge behaviors matter:
- Empty set →
itemisNone. The node returns the (still empty) set andNonefor the item rather than erroring. That's your "drained the pool" signal. - The input survives. You get a fresh set, so the original stays usable elsewhere in the graph.
If you want a seeded, reproducible pick instead, that's what this pack's pop random is for - it lets you control the selection with a seed.
Inputs and output
set(SET) - the set to pop from.set(SET, output) - the set with one element removed.item(ANY, output) - the removed element, orNoneif the set was empty.
One required input, two outputs. Wire item into whatever needs it and chain the set output back into another pop to keep draining.
Installing
It ships in Basic data handling by StableLlama. ComfyUI Manager is easiest - search "Basic data handling", install, restart ComfyUI. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Then restart. No dependencies, no model downloads - the pack is pure Python, so this installs instantly and won't touch your other custom nodes.
Common issues
The usual confusion is expecting pop to pick a specific element, or a random one - it does neither. For reproducibility, use pop random with a seed; for a specific value, use remove (which reports success) or discard (which doesn't). And if item keeps coming back None, your set is empty - check length before popping in a loop, or branch on None to exit the drain.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| set | SET | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| set | SET | — |
| item | * | — |