ComfyUI Node

index

Index — find where something lives, or get a -1 that means 'nowhere'

By StableLlama·Created about a year ago·Updated 4 days ago· 48
index
  • list
  • value
  • index
start0
end-1

index is the reverse of get item: instead of "give me what's at position 5," it answers "where does this value live?" Give it a LIST and a value, and it returns the position of that value's first occurrence as an integer. It's the node you reach for when you need to find something's place before you act on it - "which frame is the failure at?", "what position in the sweep is my target value?"

How it works

It's Python's list.index(), with the failure mode softened:

try:
    return (list.index(value, start, end),)
except ValueError:
    return (-1,)

The important difference from raw Python: a missing value returns -1, not an error. list.index() would raise ValueError and kill the node; this returns -1 so your graph keeps running. Treat -1 as "not found" and branch on it - a == -1 check feeding into if/else is the classic pattern.

Two optional inputs extend it: start (default 0) and end (default -1). Setting start limits the search to a slice of the list - useful when the same value appears multiple times and you want the second occurrence, which you'd get with index(value, first_position + 1). The default end = -1 means "all the way to the end," and the node internally converts it to the list length before searching.

Where you'd use it

  • Locating a value before modifying it. Find where a prompt is, then insert or get item at that spot.
  • Membership with position. contains only tells you yes/no; index tells you where, and -1 doubles as a no.
  • Second-occurrence hunting with a non-zero start.

Installing

Part of the "Basic data handling" pack by StableLlama. ComfyUI Manager: search "Basic data handling", install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart ComfyUI. Zero dependencies, no models - pure Python, a very low-friction install.

Gotchas worth knowing

  • -1 means "not found," and -1 is also a legal list position from the end - don't confuse the sentinel with an actual index when you feed it to get item.
  • Matching is exact equality: case, whitespace, and type all matter.
  • It returns the first occurrence unless you raise start. And it works on the pack's LIST type, not a native data list.
CategoryBasic/LIST

Inputs (4)

NameTypeDefaultDescription
listLIST
value*
startoptINT0
endoptINT-1

Outputs (1)

NameTypeDescription
indexINT