ComfyUI Node

IndexOfList

IndexOfList – ComfyUI Node

By lldacing·Created 3 years ago·Updated 8 months ago· 96
IndexOfList
  • lst
  • any
index0

What it is

IndexOfList is the plain, single-element version of list indexing: give it a list and a position, get back whatever's sitting at that position. It's the node you reach for when you're stepping through a batch or a collected set of results one at a time - most naturally inside a loop, where the index is being driven by a counter rather than typed in by hand - and need to pull out exactly one item.

The detail worth knowing up front, straight from the node's own description: if your index is out of range (index >= len(lst)), it doesn't error, it returns None. That's a deliberate design choice, and it means "did I read past the end of the list" becomes a None-check on the output rather than a try/catch around the node.

Inputs and outputs

  • lst (type *, required) - the source list.
  • index (INT, default 0, range 0–100000) - the position to pull.

One output: any (type *) - the element at that position, or None if the index is out of range.

How it works

Plain zero-based list indexing. Index 0 is the first element, same convention as Python (and most programming generally) - worth double-checking if you're used to 1-based counting from somewhere else, since off-by-one errors here are the classic bug.

Installing it

Ships in comfyui-easyapi-nodes. Via ComfyUI Manager: search "comfyui-easyapi-nodes", install, restart ComfyUI. Manual install:

cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt

No special dependency for this node, but the requirements install matters for the rest of the pack. git pull in the folder to upgrade later.

Common issues

"Downstream node crashed on a None value." That's the out-of-range case working as documented, not a bug - if index reaches or exceeds the list length, you get None back instead of an error. If you're using this inside a loop where the index climbs every iteration, that's exactly the signal you'd use to know the loop should stop; pair it with this pack's IsNoneOrEmpty to check for it explicitly, or InnerIntCompare against the list length (from GetImageBatchSize or wherever you're tracking it) to stop the loop before you ever hit an out-of-range index.

"I got the wrong element - off by one." Remember it's zero-based. Index 0 is the first item, not the last-typed "1" you might reach for out of habit.

"I need several elements at once, not just one." That's IndexesOfList - same idea, but it takes a comma-separated string of positions and returns a subset list instead of a single value.

"My list is coming from a JSON string, not a real list." Make sure whatever produced lst actually parsed the JSON into a Python list first (this pack's LoadJsonStrToList, or a comparable step) - feeding a raw JSON string in as lst will index into the string's characters rather than logical list elements, which is a subtle and confusing failure mode if you're not watching for it.

CategoryEasyApi/List

Inputs (2)

NameTypeDefaultDescription
lst*
indexINT00–100000

Outputs (1)

NameTypeDescription
any*