index
Find where a value lives in a list — -1 when it's not there
- list
- value
- index
The reverse of get item. Instead of "what's at position 3?", index answers "where is the value 42?" - it searches a data list and returns the position of the first match. Combined with the pack's get item, you can look up a value, get its position, and read it back out. That round-trip is the backbone of a lot of list-based workflow logic.
It's part of Basic data handling, StableLlama's zero-dependency utility pack.
How it works
Python's list.index(value), with the search restricted to a slice if you want it. Feed in the list and the value you're hunting; the node returns the index of the first occurrence. Two optional inputs narrow the search window:
start(INT, default 0) - where in the list to begin looking.end(INT, default -1) - where to stop. The default of-1means "to the end of the list," not "one before the end."
If the value isn't found anywhere in the window, you get -1 - Python's index() would raise an error, but this node converts that into a sentinel value you can branch on. The output index is an INT, so it wires straight into get item to re-extract the element, or into any node that wants a position.
A realistic use
Lookup-then-read is the pattern: search a list of filenames for the one containing a keyword, get its position, then use get item to pull the actual element out. Or use the -1 result as a "not present" check - the same information contains gives you, but as a number you can route anywhere.
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
- "I got -1 but the value is in the list." First check types -
2(INT) and"2"(STRING) don't match. Then checkstart/end: if you set anend, remember it's a hard stop. And it only finds the first match, so if the value appears later after an earlier miss, that's expected. - "The end input confused me."
endis exclusive, and-1is the special "rest of the list" value. Set it only when you genuinely want to stop early. - "I just wanted a yes/no." Then
containsis lighter weight. Index gives you the position; use the tool that matches the question.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| list | * | — | |
| value | * | — | |
| startopt | INT | 0 | — |
| endopt | INT | -1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| index | INT | — |