Nodes/Nilor Nodes by Nilor Corp/๐Ÿ‘บ Select Index From List
ComfyUI Node

๐Ÿ‘บ Select Index From List

Pull one item out of any list without the usual ComfyUI pain

By nilor-corpยทCreated 2 years agoยทUpdated 6 months agoยท 6
๐Ÿ‘บ Select Index From List
  • list_of_any
  • any
โ—„index0โ–บ

ComfyUI's type system makes "give me the third item in this list" annoyingly hard. Lists arrive wrapped in ways that differ per node pack, and stock nodes often refuse to accept them at all unless the socket type matches exactly. Nilor Select Index From List is the blunt instrument that solves it: it takes anything on the list_of_any socket, an index (default 0), and hands you back the single item at that position. That's the whole node.

How it pulls this off

The trick is in the class, and it's worth knowing because it explains a lot of the pack. The list_of_any input is typed with a custom AnyType (credit to pythongosssss, per the source) - a string subclass that compares equal to every type, so ComfyUI lets any socket connect to it. Under the hood the node then does a bit of defensive unpacking: if the incoming value is a list containing exactly one list, it unwraps that outer layer, and if index arrives as a list it takes the first element. It reads the actual list, checks the bounds, and returns the item.

Two behavioral details matter for beginners. The index is not negative-friendly: anything below 0 or at or above the list length raises a "Index is outside the bounds of the array" error rather than wrapping or slicing from the end. And the output is a single element - one item, not a list - so whatever you grab can be wired straight into a node that expects a scalar.

When you'd reach for it

The classic use is driving a workflow from a counter: build a list of strings (prompts, filenames, seeds), feed it here with an index that comes from a loop or a batch-size node, and you can generate "frame 3's prompt" without forking your whole graph. It pairs naturally with the other Nilor list nodes - ๐Ÿ‘บ List of Ints to make the index list, this one to dereference it. Because it accepts any type, it also works on image batches and tensor lists, not just strings, which is why the type on the output socket is the same wildcard any.

Install

ComfyUI Manager (search "Nilor Nodes") or:

cd ComfyUI/custom_nodes
git clone https://github.com/nilor-corp/nilor-nodes
cd nilor-nodes && pip install -r requirements.txt

Restart ComfyUI. This node needs none of the pack's exotic dependencies - no SQS, no opencv, nothing. The pack does load scipy at startup though, so if the whole pack fails to import, that's the first thing to check (pip install scipy); it's imported at module level even though this node never touches it.

Traps worth naming

Out-of-bounds is the failure mode people actually hit - the error is descriptive but it's a hard stop, so if you're indexing into a list whose length you've computed elsewhere, add a guard or use a node that clamps. The INPUT_IS_LIST = True flag is subtle too: it tells ComfyUI to hand the node the whole list as one argument rather than expanding it, which is exactly what you want here - it's also why feeding it a list-of-lists sometimes needs that one-layer unwrap. For anything fancier - negative indexing, modulo wrapping, multiple selections - you'd be better off in WAS Suite or a tiny custom node, but for "item N of this list, please," this is about as frictionless as ComfyUI gets.

CategoryNilor Nodes ๐Ÿ‘บ/Utilities

Inputs (2)

NameTypeDefaultDescription
list_of_any*โ€”
indexINT0โ€”

Outputs (1)

NameTypeDescription
any*โ€”