ComfyUI Node

List Slicer

The list version of 'give me items 3 through 7'

By DebugPadawan·Created about a year ago·Updated 5 months ago· 2
List Slicer
  • input_list
  • list_slice
  • count
start0
end1

Slicing is the operation people assume ComfyUI just has: "give me the first three items," "skip the first item," "take this range." It doesn't - you build it. List Slicer is that built-in, with start and end indices and a count so you know what you actually extracted. It's the list cousin of the pack's Image Batch Slicer, applied to any LIST.

It's part of DebugPadawan's ComfyUI Essentials, a small MIT-licensed utility pack with a full family of list nodes.

How it works

start is inclusive, end is exclusive - the standard Python convention. start = 2, end = 5 on a ten-item list gives you items 2, 3, and 4. Two behaviors are worth knowing exactly:

  • end is exclusive. Item at position end is not included. The most common off-by-one in the whole pack.
  • "To the end" happens whenever end <= start. The README's shorthand is "use 0 for to the end," but the code is broader: if your end index is at or below the start index, the node treats it as "give me everything from start onward." That means end = 0 works for to-the-end, and so does accidentally setting end below start - you get a full tail slice instead of an error.

Inputs and outputs

  • input_list - the LIST to slice.
  • start - inclusive start index, default 0.
  • end - exclusive end index, default 1. end <= start means "to the end."

Outputs: list_slice (LIST) and count (INT - how many items you got).

Install

Standard custom-node fare:

cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git

Restart ComfyUI, or install via ComfyUI Manager by searching "DebugPadawan". requirements.txt lists numpy, torch, and opencv-python - numpy and torch already ship with ComfyUI and the shipped code never imports cv2, so no heavy downloads, no model files, no API keys.

Where people get burned

  • The exclusive end. start = 0, end = 3 gives three items (0, 1, 2), not four. If your slice is always one short, this is why.
  • No negative start. start is clamped to >= 0; if you wanted "everything except the last item," you can't say end = -1 - negative ends get treated as to-the-end too. Work around it by slicing a length, or use List Info's count in a math node.
  • Silent to-the-end. Because any end <= start means "rest of list," a buggy end value won't error - it'll just quietly give you the tail.

A typical pattern: slice off the first N items for one processing branch while the tail flows elsewhere, then check the count output to confirm you split where you thought you did.

CategoryDebugPadawan/List

Inputs (3)

NameTypeDefaultDescription
input_listLIST
startINT0
endINT1

Outputs (2)

NameTypeDescription
list_sliceLIST
countINT