ComfyUI Node

SliceList

Python-style list slicing as a ComfyUI node

By lldacing·Created 3 years ago·Updated 8 months ago· 96
SliceList
  • lst
  • lst
start_index0
step1
end_index100000
reversefalse

If you've ever wanted "just the first five items," or "every other one," or "the list, but backwards," out of a list wire in ComfyUI, you've wanted SliceList. It's Python's list[start:end:step] syntax, minus the actual Python - four number/boolean widgets standing in for slice notation, wired straight into your graph.

How it works

The node takes whatever list you feed into lst - this pack's wildcard * type, so it doesn't care whether it's a list of strings, ints, floats, bboxes, or anything else a typed list can hold - and returns the slice defined by start_index, end_index, and step, same semantics as Python slicing. Set start_index to 2 and you skip the first two elements. Set step to 2 and you take every other one. The reverse boolean flips the order of what comes out.

The one behavior worth knowing before you rely on it: the node's own description says that if lst isn't actually a list - wrong wire type, or something upstream that resolved to a single value instead of a list - it returns None rather than erroring. That's a quiet failure mode: None doesn't crash the graph on the spot, it just propagates into the next node, which then usually does error, in a way that points at the wrong place. If a downstream node complains about a missing or None input, walk back to the nearest SliceList (or any list-typed node) and check that what's feeding it is genuinely a list, not a single item that never got wrapped.

Inputs and outputs that matter

  • lst (required, any type) - the list to slice.
  • start_index (default 0, range −100000 to 100000) - where the slice begins.
  • end_index (default 100000) - where it ends. The huge default is effectively "no limit," so leaving it alone keeps everything from start_index onward.
  • step (default 1) - the stride. 2 skips every other element; a negative step is where things get interesting if you're also using reverse, so test small before trusting it in a big pipeline.
  • reverse (default false) - reverses the sliced result.

Output: a single lst, the sliced (and possibly reversed) list, ready to feed into a loop node (ForEachOpen/ForEachClose from the same pack), an IndexOfList, or straight back into whatever was consuming the full list before.

Installing it

ComfyUI Manager: search comfyui-easyapi-nodes. Manually:

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

Restart. SliceList is plain Python list-slicing - no models, no extra downloads.

Where people get tripped up

The big one is the None-on-non-list behavior described above - it's documented but easy to forget, and because it fails silently at the SliceList node itself, the actual error message shows up one or two nodes downstream, which sends people debugging the wrong node. Second: start_index/end_index/step all have generous ±100000 ranges, which is friendly for typing large lists but also means an out-of-range index doesn't get flagged - it just clamps or comes back empty depending on where you set it, same as Python slicing does. If a slice comes back shorter than you expected, print the length of lst before assuming the slice logic is wrong; it's usually that the input list was smaller than you thought.

CategoryEasyApi/List

Inputs (5)

NameTypeDefaultDescription
lst*
start_indexINT0-100000–100000
stepINT1-100000–100000
end_indexINT100000-100000–100000
reverseBOOLEANfalse

Outputs (1)

NameTypeDescription
lst*