ListItemExtract
Pull one item out of a list in ComfyUI, no regex required
- STRING
ComfyUI doesn't really do lists. Not the way you'd like, anyway. Arrays travel around the graph as text - comma-separated strings, or stringified Python literals like ['dog', 'cat', 'rabbit'] - and grabbing item #2 out of one usually means a sad little chain of Regex nodes. ListItemExtract exists so you don't have to do that.
It comes from drmbt/comfyui-dreambait-nodes, a personal grab bag of forks and quality-of-life utilities. This is the tiny, no-surprises end of that pack: feed it a list and an index, get one item back as a string. That's the whole job, and it does it without complaining.
How it works
The input you actually set is list_input (STRING). Note that it's a string, not a real array - this matters. The node tries to parse it with Python's ast.literal_eval. If it parses as a list, you're indexing into multiple items. If parsing fails, the whole string is treated as a single item.
So "['dog', 'cat', 'rabbit']" gives you three items, but "dog, cat, rabbit" gives you one. The comma-separated form won't split, which is the classic footgun here because most other text-list nodes in the ecosystem do split on commas. Feed it a proper bracketed string, or the output of a node that produces one - the same pack's TextLinesToList fits the bill.
The other input is index (INT, default 0, minimum 0). That's it. Two inputs, one output.
The output
A single STRING - the selected item, converted to a string if it wasn't already. It's a plain text wire, so it goes anywhere a string goes: a prompt field, a filename, a condition in a switcher, whatever.
Where people get burned
- Out of range doesn't error. Instead of failing, it clamps to the last item and logs a warning. That's convenient in a loop that overshoots, and quietly dangerous when you wanted an error to catch a bug.
- No negative indexing.
indexbottoms out at 0, unlike its sibling node ListItemSelector which happily takes-1for "the last one." If you need the tail, compute the length yourself first. - Comma-separated strings don't split. Worth repeating, because it's the one that bites everyone.
Install
Install it the standard custom-node way:
cd ComfyUI/custom_nodes
git clone https://github.com/drmbt/comfyui-dreambait-nodes
Then restart ComfyUI. If you use ComfyUI Manager, search for comfyui-dreambait-nodes there instead and let it handle the install. Heads up: the pack's requirements.txt pulls in a lot - transformers, torchaudio, librosa, bitsandbytes, moviepy and friends - because it's a grab bag. The first install takes a while even if you only wanted this one node.
It's a thin node, and that's fine. Sometimes you want a boring utility you can trust at 2am.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| list_input | STRING | — | |
| index | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |