ComfyUI Node

pop

Pop an item off a list and keep the leftover list too

By StableLlama·Created about a year ago·Updated 4 days ago· 48
pop
  • list
  • list
  • item
index-1

"Pop" is one of those programming words that means something very specific: remove an item and get it back at the same time. That's exactly what DataListPop does - you feed it a list and it gives you two things: the list with the item removed, and the item itself.

The inputs are list (any type) and an optional index, which defaults to -1. That default is the key detail: with no index wired in, it removes and returns the last item, matching Python's list.pop(). Wire in an index and it removes that position instead. Index 0 pops the first item, 2 pops the third, and so on.

Why the two outputs matter

This is the node's real superpower, and it's easy to miss. Because you get both the trimmed list and the popped item, you can do two things at once in a workflow: keep the remaining list flowing down one branch while the removed item goes somewhere else - a display node, a text encoder, a save step. You never have to reconstruct "everything except X" yourself.

The mechanism is straightforward: the node copies the list, pops at the index, and returns both halves. It's careful not to mutate your original list - useful in ComfyUI, where a node that changes its input in place can produce confusing results on re-runs.

The empty-list behavior

If the list is empty, you get None for the item and the (still empty) list back - no crash. If the index is out of range, same graceful None. It's not the loudest failure mode in the world, so if you're popping by index and getting None mysteriously, count your list first with DataListLength. For the "just grab something, I don't care which" case, the pack's pop random node is the sibling you want.

Installing it

Part of StableLlama's Basic data handling pack - pure Python, zero dependencies, no model downloads. Install the pack once, get every node in it:

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

Restart ComfyUI afterward, or use ComfyUI Manager: search "Basic data handling" and install. No requirements.txt headache, because there are no third-party dependencies to conflict with anything else in your setup.

Common issues

The one thing that consistently confuses people is feeding it a single LIST variable instead of a data list - if the whole collection is packed into one value, you'll pop that one value and wonder where your data went. Keep your collection as a native data list (or convert first) and pop behaves exactly like the Python it's named after.

CategoryBasic/Data List

Inputs (2)

NameTypeDefaultDescription
list*
indexoptINT-1

Outputs (2)

NameTypeDescription
list*
item*