set item
Swap one item in a list without rebuilding it
- list
- value
- list
Lists are nice, but sometimes one element is just wrong and you want to replace it in place - not pop it and re-append, not rebuild the whole thing. DataListSetItem does exactly that: it takes a list, an index, and a replacement value, and returns a new list with that one spot swapped out.
Inputs: list (any type), index (defaults to 0), and value (any type). Output: the updated list. Feed it ["a", "b", "c"] with index=1, value="z" and you get ["a", "z", "c"].
How it works
Under the hood it's Python's list[index] = value on a copy of your input. Two details worth knowing:
- It copies first, so your original list isn't mutated - re-runs stay consistent.
- Indexing follows Python rules, including negative indexes:
index=-1replaces the last element. That's a handy way to patch the final item without knowing the list's length.
If the index is out of range, this node raises an error rather than quietly doing nothing. That's deliberate - a silent "I replaced nothing" is how data bugs sneak through. If you see a crash here, count your list with DataListLength and check your index math.
Why you'd reach for it
The standout use is injecting a single value into a list that was built elsewhere. Say you generate a list of prompts, then want to swap in one corrected prompt at position 2 without touching the others - done. It also pairs with DataListRange or an index output from a loop to patch the Nth element programmatically. If you need to insert (grow the list) rather than replace, that's DataListInsert; this node never changes the list length.
One word of caution: replacing an element with a different type than its neighbors is allowed, and it'll usually work - but downstream nodes that assumed homogeneous lists can get confused. Keep the type consistent unless you know what you're doing.
Installing it
Part of StableLlama's Basic data handling pack - pure Python, zero dependencies, no models:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart ComfyUI, or search "Basic data handling" in ComfyUI Manager and install. There's no requirements.txt friction because the pack uses only the standard library.
Common issues
The out-of-range error is the main thing that'll bite - and negative indexes, if you forget they're supported, can produce "wait, which item did I just change?" moments. And the pack-wide reminder: this operates on a data list, not a single LIST variable, so convert first if that's what you're feeding it.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| list | * | — | |
| index | INT | 0 | — |
| value | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| list | * | — |