set item
Replace the item at any position in a list
- list
- value
- LIST
Swap one item out, keep the rest of the list
Sometimes you don't want to add to a list or remove from it - you want to replace a single slot. Say a list of prompts where the third one is stale, or a list of seeds where one value is cursed. This node does exactly that: give it a list, an index, and a new value, and it returns a new LIST with that one position swapped.
It's the "edit in place" member of the pack's list family, alongside append, insert, and remove. If you know where the problem item lives, this is more surgical than removing and re-inserting.
How it works
Mechanically it's Python's list[i] = value on a copy - the input LIST is duplicated first, so the original is never mutated, then the item at the given index is replaced. Default index is 0, so if you forget to set it you'll overwrite the first item, which is a fun way to lose your list's head.
One sharp edge: if the index is out of range, the node raises an error rather than silently doing nothing. You'll see a red-bordered node with a message like "Index 10 out of range for LIST of length 5". That's intentional - a silent no-op would let a bad index corrupt your workflow invisibly. If you're feeding an index that might be out of bounds, clamp it first with the pack's comparison/math nodes.
Inputs and outputs
- list (LIST) - the list to edit.
- index (INT, default
0) - which position to replace. Python convention: negative indices count from the end (-1= last). - value (*) - the new item. Wildcard input, so it accepts whatever type your list holds.
Output is a single LIST: the original with the one item swapped. Everything else - order, length, the other values - is untouched.
Installing it
This comes from Basic data handling by StableLlama, the r/StableDiffusion regular whose model writeups (Flux Klein 9B, RealVisXL) are better known than his code. The pack is deliberately lightweight: zero runtime dependencies, no model downloads, no GPU involvement. It's the kind of pack that just works after a restart.
Install via ComfyUI Manager (search "Basic data handling") or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart ComfyUI; it lives under Basic/LIST.
Troubleshooting
The two failure modes are forgetting the default index is 0 (you overwrite the first element when you meant to leave it alone) and hitting an out-of-range index (which errors loudly - check your list length against your index). Also remember this is the pack's LIST type, not ComfyUI's native data list; a native data list won't plug into the input.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| list | LIST | — | |
| index | INT | 0 | — |
| value | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LIST | LIST | — |