Nodes/ComfyUi-MpiNodes/Mpi List Range
ComfyUI Node

Mpi List Range

Slice a list with inclusive, negative-index friendly bounds

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi List Range
  • list_input
  • list
  • count
start0
end-1

Python people, stop here for a second: Mpi List Range's end index is inclusive, which is not how Python slices work, and it will bite you exactly once. Start at 0, end at 2, and you get three items - indices 0, 1, 2 - not two. Read that tooltip ("End index (inclusive). Negative counts from end. -1 = last item.") and the shape of the whole node becomes clear: it's designed the way a human counts, not the way a range() call counts.

The job is simple: list_input is any list, start and end pick a sub-range, and out the other side you get the sliced list plus its count. Negative indices count from the end, so start = -2 grabs the last two items, and the default of end = -1 means "up to and including the last item" - which in the inclusive world is "the whole tail," not "everything but the last one." This is the node for "give me the first half of these prompts" or "I only want the last frame of this batch."

It's also clever about what a "list" is. Image batches arrive as a tensor shaped [B, H, W, C], and if the node just sliced the Python list wrapper it would hand back the whole batch every time. So it checks for that case and slices along the batch dimension instead - start/end become frame indices on a video or image batch, not positions in a one-element list. That makes it genuinely useful for frame selection in video work: slice frames 0–24 out of a 96-frame clip and feed the cut to a sampler.

Outputs: list (marked as a list type, so it feeds list consumers properly) and count (the length of what you got back - handy if you're feeding it into math or an MpiListCount-style check downstream). Pair it with MpiIsListEmpty or MpiListCount when the slice might come up empty, so your graph routes around a zero-length result instead of crashing on it.

One honest caveat: inclusive end means "start 0, end 4" is five items, which is one more than the four you probably meant if you're used to half-open ranges. It's the only real gotcha, and it's a consistent one - everything else about the node behaves as labeled. If you ever get a slice that's one item longer than expected, you now know why.

Installing is the pack's standard no-drama procedure: ComfyUI Manager → search "ComfyUi-MpiNodes" → install → restart, or

cd ComfyUI/custom_nodes
git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes

No dependencies, no models - pure Python from the Mad Pony Interactive utility pack (the engine behind Cubric Vision). A small slicing node with one gotcha in the docs and one genuinely thoughtful batch-dimension behavior.

CategoryMpiNodes/Logic

Inputs (3)

NameTypeDefaultDescription
list_input*
startINT0-18446744073709550000–18446744073709550000Start index (inclusive). Negative counts from end.
endINT-1-18446744073709550000–18446744073709550000End index (inclusive). Negative counts from end. -1 = last item.

Outputs (2)

NameTypeDescription
list*
countINT