List Slice
Python slicing, as a node
- ANY
- data
list_Slice is the smallest, most honest utility node in the ComfyUI_Swwan pack: it takes a list, cuts it from start to end, and hands you back the slice. If you've ever written frames[2:10] in Python and wished you could do the same thing inside a workflow, this is that thought turned into a node.
It's the sibling of BatchSlice in the same Apt_Preset/data/😺backup category. The practical difference: BatchSlice declares a LIST-typed input; list_Slice takes an Any input and always outputs a list. So if your upstream produces an arbitrary list type - strings, images, latents, whatever - and you just want the middle chunk, list_Slice is the more permissive of the two.
How it works
Three inputs: ANY (the list to slice - marked forceInput, so ComfyUI treats it as data rather than a widget), start (default 0), and end (default -1, i.e. "to the end").
The semantics are Python's slice semantics, ported faithfully:
- Inclusive start, exclusive end.
start=2, end=5returns items 2, 3 and 4. - Negative indices work.
start=-3means "start three from the end," sostart=-3, end=-1grabs the third-from-last and second-from-last items. - Everything clamps. Out-of-range values are clamped to the list bounds instead of erroring.
- Empty slices are valid. If
startlands pastend, you get an empty list back, not a crash.
One subtlety: because the input is INPUT_IS_LIST, ComfyUI hands the node the whole list and it does its own indexing - so this node plays nicely with lists coming out of other list-aware nodes, including the pack's list_Merge and Image Batch to Image List. Output is always a list, marked as such, so it feeds back into the same family.
Installing it
It ships in ComfyUI_Swwan:
cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
pip install -r ComfyUI_Swwan/requirements.txt
Or install the pack via ComfyUI Manager, search "ComfyUI_Swwan".
Where people get burned
The exclusive-end off-by-one is the eternal trap - end is not the last item you keep, it's one past it. And unlike BatchSlice, there's no tensor-stacking nicety here: the output stays a plain list, so if you slice a list of images and the next node wants a batched tensor, you'll need the list-to-batch converter in the chain. Also worth knowing: start=0 with the default end=-1 is a no-op pass-through, which some people use deliberately as a "prove the list is connected" node - but it adds no value over just wiring through, so don't.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| ANY | * | — | |
| start | INT | 0 | — |
| end | INT | -1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| data | * | — |