insert
Put an item at any position — not just the end
- list
- item
- list
append only knows one place to put things: the end. insert is the node for when "the end" isn't good enough - it drops an item at any position you specify, shoving the rest of the list down to make room. It's the fine-grained list editor of the Data List family.
It's part of Basic data handling, StableLlama's zero-dependency utility pack.
How it works
Python's list.insert(index, item), on a copy of the input list (it returns a new list rather than mutating, so it chains cleanly in a graph). Give it a list, an index, and an item, and the item lands at that position with everything after it shifted right. A few indexing notes that behave just like Python:
- Insert at
0to prepend - item becomes the new head. - Insert at the list's length to effectively append.
- Inserting past the end just appends; negative indices count from the end.
The output list is a data list, so the modified collection keeps flowing as a batch.
The inputs and output
list(*) - the list to modify.index(INT, default 0) - where the item goes.item(*) - the value to insert.list(output) - the new list with the item in place.
A realistic use
Order matters when position encodes meaning - say a list of style tags where the first entry controls the dominant look, or a sequence of prompts meant to run in order. Insert lets you prepend a global instruction before a computed batch, or splice a value into the middle of a list you've assembled incrementally.
Installing it
ComfyUI Manager → search "Basic data handling", or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart. No dependencies, no models.
Common issues
- "The item went to the end and I wanted the middle." Check your index - inserting at a value larger than the list length appends. And remember indexing starts at zero.
- "I wanted it at the front." Insert at index
0. It's the same node, just set the position. - "This didn't mutate my original list." Correct - the node returns a new list. If you're seeing the old list downstream, you wired the output from the wrong place; the original input list is untouched by design.
- "I'm really just adding to the end." Then
appendorextendis simpler and says what you mean. Insert earns its keep only when the position actually matters.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| list | * | — | |
| index | INT | 0 | — |
| item | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| list | * | — |