slice
Cut a list down to just the slice you need
- list
- LIST
Take a subsection of a list without touching the rest
Lists get long. Sometimes you only want a piece of one: the first five prompts, items 10 through 20, every other seed in a batch. This node is Python's slice syntax - list[start:stop:step] - wrapped in a ComfyUI node, and it's one of the handiest of the pack's list utilities once your lists grow past a handful of items.
The whole idea is that you don't rebuild lists by hand; you carve the one you've got. It's also the natural partner to "range": range builds a sequence, slice trims any LIST down to a window of it.
How it works
The node returns list[start:stop:step]. Three things to internalize from Python slicing:
- stop is exclusive. A slice from
0to3gives you items 0, 1, 2 - not 3. This trips up every newcomer at least once. - The default stop is huge (
32767in the UI), which is a deliberate trick: leave stop alone and the slice runs to the end of the list. The comment in the source even says "the computer can do more but be nice to the eyes." - Negative step works.
step=-1with sensible start/stop gives you a reversed slice, and negative indices count from the end, sostart=-3grabs the last three items.
Unlike the pack's reverse and sort nodes, this one can change the length of your list, which makes it the go-to for "I need exactly N of these."
Inputs and outputs
- list (LIST) - the list to slice.
- start (INT, default
0) - first index included. - stop (INT, default
32767) - cut off here (exclusive). - step (INT, default
1) - spacing;2= every other item,-1= reversed.
Output is a single LIST: the subsection. Original list is untouched - the node slices a fresh view.
Installing it
Ships in Basic data handling by StableLlama, the r/StableDiffusion regular whose long model writeups (Flux Klein 9B, RealVisXL) are more famous than his code. The pack is minimal by design: zero runtime dependencies, no model downloads, nothing that can fight with your environment.
Install via ComfyUI Manager (search "Basic data handling") or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart ComfyUI; it's under Basic/LIST.
Troubleshooting
The stop-is-exclusive trap is the number-one offender - you set stop to 5 and get four items, so you nudge it to 6 and get five. Second: a step of 0 is invalid in Python slicing and will error, so leave step at 1 unless you mean it. And remember the input expects the pack's LIST type; a native ComfyUI data list won't connect directly. Slice first, then convert if you need items to fan out individually.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| list | LIST | — | |
| startopt | INT | 0 | — |
| stopopt | INT | 32767 | — |
| stepopt | INT | 1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LIST | LIST | — |