PyList: Slice
Slice — Python list[start:end] without leaving the graph
- PYLIST
- PYLIST
If you've ever written my_list[2:5] in Python, you already know how PyList: Slice behaves - because it's literally that expression exposed as a node. Give it a PyList and a start/end pair, and you get back a new PyList containing just those items. It's the node you grab when you want the first three of your ten prompts, or everything except the last entry, without converting anything out of list form.
It looks trivial, and it mostly is. But there's one footgun in the defaults that will absolutely hand you an empty list the first time you wire it up, so read the input section before you hit Run.
How it works
The run() method is return (PYLIST[start:end],) - a straight Python slice with standard semantics. The author's tooltip says it plainly: the item at end is not included, negative indices count from the end of the list, and out-of-range bounds are silently clamped rather than erroring. start defaults to 0, so a slice of [2:5] gives you items 2, 3, 4 - three items, not four.
The inputs that matter
- PYLIST - the list to slice,
forceInput, so it must be connected from a PyList-producing node. - start - first index to keep, default
0. - end - index where slicing stops, exclusive, default
0.
The output is a single PYLIST socket.
And here's the trap: both widgets default to 0. PYLIST[0:0] is an empty list. So if you drop this node in, connect it, and don't touch the widgets, you get nothing back - the queue will run fine and produce an empty array, which then silently does nothing downstream. It's not a bug, it's just an unfortunate default, but it's the single most common way people get burned by this node. Set end to something real and you're fine.
When you'd actually use it
PyList operations are at their most useful while the data is still one value, before you cross into per-item processing. Common cases:
- Take the first N of a batch of prompts or seeds (
start=0, end=N). - Drop the last item (
end=-1), e.g. to discard a final placeholder entry from a range you generated. - Grab a middle window, or even a reversed-ish selection with negative start.
Then, when the surviving items need to run through the graph individually, chain PyList To List afterward. Slicing first, converting second, is the pattern this node exists for.
One more Python quirk worth remembering: negative end counts from the end, so [0:-1] drops only the last item, and a slice like [1:-1] strips the first and last elements in one go. Handy for trimming generated ranges without knowing their length.
Installing it
Part of godmt/ComfyUI-List-Utils, found under the list_utils category. ComfyUI Manager users just search "ComfyUI-List-Utils" and install; manual install is the usual:
cd ComfyUI/custom_nodes
git clone https://github.com/godmt/ComfyUI-List-Utils
Then restart ComfyUI. No models to download, no extra dependencies - the slice node is pure list slicing with nothing imported, so there's nothing to configure or break after install.
Common issues
The empty-slice default is the big one, covered above. After that, the usual confusion is people expecting end to be inclusive (it isn't) or forgetting that a PyList slice stays a PyList - it doesn't trigger per-item execution by itself, so a slice that "looks right" but feeds a node that ignores lists may appear to do nothing. If that's you, add PyList To List after the slice and the batch behavior kicks in. Otherwise, this node is about as low-drama as List-Utils gets: set end, run, done.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| PYLIST | PYLIST | Connect the PyList to slice. | |
| start | INT | 0-9007199254740992–9007199254740992 | Slice start index, matching Python list[start:end]. |
| end | INT | 0-9007199254740992–9007199254740992 | Slice end index. The item at this index is not included. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PYLIST | PYLIST | The sliced PyList. |