SP_SelectItemFromAnyList
Pull the Nth item, and don't crash if you overshoot
- any_list
- *
Lists are everywhere in ComfyUI once you start doing parameter sweeps or batch work - a list of prompts, a list of seeds, a list of checkpoint names. What's missing from core ComfyUI is a simple, forgiving way to say "give me item number 3 out of whatever that list turned out to be." SP_SelectItemFromAnyList is exactly that, nothing more.
What it does
Two required inputs: any_list, which accepts a list of literally any type, and index, an integer defaulting to 0. The node's own tooltip on index says it plainly - "the index of the item you want to select from the list" - and the description backing the node spells out the one behavioral detail that actually matters: if the index you gave is out of range, it doesn't error, it just returns the last item in the list. One output, the selected item, typed as "any" so it fits wherever the list's contents belong.
That clamping behavior is the whole reason to pick this over rolling your own indexing logic. If you're driving index from something dynamic - a batch counter, a value coming out of another list-processing node in this same pack - you don't have to separately guard against running past the end of the list. Overshoot, and you just get whatever the last entry was, instead of the workflow dying mid-run.
Where it fits
This is the natural partner to any node in SP-Nodes that produces a list - SP_XYValues turning a block of newline-separated text into a typed list, or StrToCombo, or output from your own list-generating logic. Build the list once, then use SP_SelectItemFromAnyList wherever you need to peel off a specific entry rather than iterate the whole thing. It's a small node, but it's the kind of small node that quietly removes a class of "list index out of range" errors from a workflow that's driving itself off dynamic data.
Installing it
Ships with the SP-Nodes pack:
- ComfyUI Manager: search "SP-Nodes", install, restart.
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/bananasss00/ComfyUI-SP-Nodes, restart ComfyUI.
No models or heavy dependencies - pure list indexing, nothing to download.
Troubleshooting
Because the input and output are both the wildcard "any" type, ComfyUI's own type-checking can't catch a mismatch for you the way it would with a typed connection - if any_list isn't actually a list (say something upstream produced a single value instead), you'll find out at execution time rather than when you wire it up. If you get an unexpected error here, the first thing to check isn't this node, it's whatever fed it: confirm the upstream node is actually marked to output a list and not a single value. Beyond that there's nothing exotic going on - it's list indexing with one deliberate safety net, and that net is the only thing distinguishing it from list[index] in plain Python.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| any_list | * | — | |
| index | INT | 00–9223372036854776000 | The index of the item you want to select from the list. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |