ComfyUI Node

insert

Insert — put an item in the middle, not just at the end

By StableLlama·Created about a year ago·Updated 4 days ago· 48
insert
  • list
  • item
  • LIST
index0

append adds to the end; insert adds where you say. Give it a LIST, an index, and an item, and you get back a new LIST with the item slotted in at that position, everything after it shifting down one. It's the node for "I need this value at position 2, not at the end," which comes up more than you'd think once workflows start assembling ordered collections.

How it works

It's Python's list.insert() behind a copy-first wrapper:

result = list.copy()
result.insert(index, item)
return (result,)

The original list is untouched - new list out, input preserved. The item accepts any type (*), so you can insert a number, a string, or a whole nested structure. The index input defaults to 0, which means the default behavior inserts at the front - a trap if you leave it alone expecting an append. And because this is Python's insert, an index larger than the list just appends rather than erroring: insert([1, 2], 99, "x") gives [1, 2, "x"]. No crash, just a silent append you might not have meant.

Output is a single LIST.

Where you'd use it

  • Ordered assembly. Slip a value into its correct position instead of appending and resorting.
  • Priority insertion. Add a "high priority" item at the front with index = 0.
  • Mixing with index. Use the index node to locate a spot, then insert relative to it.

Installing

It's in the "Basic data handling" pack by StableLlama. ComfyUI Manager: search "Basic data handling", install, restart. Or:

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

Restart ComfyUI. Zero dependencies, no models - pure Python, one of the easiest installs in the ecosystem.

Gotchas worth knowing

  • Default index is 0 - if you forget to set it, you're inserting at the front, not the back.
  • Out-of-range indices append silently rather than erroring. If you expected an error to catch a bad index, you won't get one.
  • Inserting into the middle is O(n) - irrelevant for workflow-sized lists, but don't build a loop that inserts one item at a time into a big list.
  • It operates on the pack's LIST type, not a native data list.
CategoryBasic/LIST

Inputs (3)

NameTypeDefaultDescription
listLIST
indexINT0
item*

Outputs (1)

NameTypeDescription
LISTLIST