ComfyUI Node

slice

Grab a chunk of a list, not the whole thing

By StableLlama·Created about a year ago·Updated 4 days ago· 48
slice
  • list
  • list
start0
stop32767
step1

Slicing is the Swiss Army knife of list handling - "give me items 2 through 5," "every other item," "everything from the third item on." DataListSlice brings Python slicing to the node graph, and it's the node you'll reach for whenever you need part of a list rather than all of it.

Inputs: list (any type), plus three optional integers - start (default 0), stop, and step (default 1). Output: the sliced list.

How it works

Under the hood it's Python's list[start:stop:step], so you're getting real Python slice semantics:

  • start - where the slice begins (inclusive).
  • stop - where it ends (exclusive). The default here is a huge sentinel value (32767), which effectively means "to the end of the list" - so leaving it untouched gives you the rest of the list from start on.
  • step - the stride. step=2 gives you every other item; step=-1 gives you the whole list reversed, a neat trick that overlaps with DataListReverse.

Because it's real Python slicing, negative values work too: start=-3 with no stop grabs the last three items. That's the quick "tail of the list" move.

Why you'd use it

This is the workhorse for dealing with oversized batches. Take a 100-item list of prompts and process only the first 10 with a slice. Split a list in half for parallel branches - slice 0:50 and 50:100. Thin out a list with a step for quick previews. Pair it with DataListShuffle to deal a random subset: shuffle, then slice the first N. It's hard to overstate how often "I just need a chunk of this" comes up once you have the node.

Installing it

Part of StableLlama's Basic data handling pack - pure Python, zero dependencies, no models:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart ComfyUI, or search "Basic data handling" in ComfyUI Manager. The pack has no requirements.txt worth worrying about.

Common issues

The exclusive stop trips everyone up at least once - 0:5 gives items 0 through 4, not 5. If you want exactly five items starting at 0, that's stop=5. Also remember the default stop is "basically the end," so if you set start and nothing else, you get the tail of the list, which is usually what you wanted anyway. And as always with this pack, it operates on a data list; convert a single LIST variable first if that's what you're feeding it.

CategoryBasic/Data List

Inputs (4)

NameTypeDefaultDescription
list*
startoptINT0
stopoptINT32767
stepoptINT1

Outputs (1)

NameTypeDescription
list*