List Switch By Index ♾️Mixlab
Merge two inputs into a list and pick by position
- A
- B
- list
- count
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-1it 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 -
onflattens nested lists into a single flat list;offleaves the nesting. Reach foronwhen 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.
indexis at its-1default, 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
flattoonto 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.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| index | INT | -1-1–1000 | — |
| flat | COMBO | 2 options: off, on | |
| Aopt | * | — | |
| Bopt | * | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| list | * | — |
| count | INT | — |