Nodes/comfyui-mixlab-nodes/List Switch By Index ♾️Mixlab
ComfyUI Node Runs on cloud

List Switch By Index ♾️Mixlab

Merge two inputs into a list and pick by position

By MixLabPro·Created 3 years ago·Updated 2 months ago· 1,859
List Switch By Index ♾️Mixlab
  • A
  • B
  • list
  • count
index-1
flat

A small routing utility. Give it up to two inputs, and it combines them into one list and lets you pull out an item by its position - or hand back the whole combined list. Because its sockets are wildcard-typed, it works on anything: images, latents, strings, conditioning. It's the kind of node you don't think about until you're wiring a graph that needs to concatenate a couple of sources or select one of them by number.

How it works

You connect something to A and something to B (each can be a single item or already a list). The node stitches them into a single list. The index then decides what comes out: pick a position to grab that one item, or leave it at -1 to pass the entire combined list through. The flat toggle controls whether nested lists get flattened into one level or kept as-is. Alongside the result you get a count so you know how many items you're dealing with.

Think of it as two jobs in one node: combine (glue A and B together) and switch (select by index). Which one you're using depends on whether you set an index or leave it at -1.

The inputs that matter

  • index - the position to select (default -1). At -1 it returns the whole combined list; set a real position to pull a single item out. This is the knob that turns "merge" into "pick."
  • flat - on flattens nested lists into a single flat list; off leaves the nesting. Reach for on when you've fed it lists-of-lists and want them collapsed.
  • A and B (optional) - the two wildcard inputs to combine. Wire in whatever type you're routing; they don't have to be the same kind, though keeping them consistent is saner for whatever consumes the output.

Outputs: list (the combined/selected result, itself a list) and count (an INT - how many items). Wire list into whatever needs the merged or selected value; count is handy for driving a loop or a downstream index.

Installing it

Get the pack via ComfyUI Manager (search mixlab, install comfyui-mixlab-nodes, restart), or clone it:

cd ComfyUI/custom_nodes
git clone https://github.com/shadowcz007/comfyui-mixlab-nodes

then install requirements and restart. No downloads - it's a pure utility.

Common snags

  • You expected one item, got the whole list. index is at its -1 default, which means "return everything." Set an actual position to select a single item.
  • Index out of range. Ask for position 5 in a 3-item list and it can't give you that. Use the count output to know the valid range, or wire count in to keep your index honest.
  • Nesting surprises. If a downstream node chokes on the shape, flip flat to on to collapse nested lists into a flat one.
  • Type mismatch downstream. The wildcard sockets accept anything, but the node that consumes the output still cares. Feed it types that make sense together, and make sure the receiver expects a list.
Category♾️Mixlab/Utils

Inputs (4)

NameTypeDefaultDescription
indexINT-1-1–1000
flatCOMBO2 options: off, on
Aopt*
Bopt*

Outputs (2)

NameTypeDescription
list*
countINT