ListSlice (Yogurt Nodes)
Slice a list the Python way — mind the stop value
- list_data
- slice
Sooner or later you don't want an entire list - you want the first three frames, everything except the last item, or the list backwards. YogurtListSlice is the node for that. It takes any list and returns a sub-list using Python's native slice semantics: start is included, stop is not, and negative numbers count from the end.
It's part of ComfyUI-YogurtNodes, yogurt7771's all-in-one pack of 150+ nodes. The pack has no community reputation to speak of - it's a one-person, MIT-licensed grab-bag with a half-machine-generated README - but the list utilities are cleanly done, and Slice is the one with actual Python gotchas hiding inside.
How it works
list_data (any list) plus three INTs: start (inclusive, default 0), stop (exclusive, default -1), and step (default 1). Two booleans sit alongside: use_none_start and use_none_stop. Those exist because ComfyUI can't easily express Python's None slice bounds - None means "from the beginning" or "to the end", and the booleans fake it for you.
Here's the trap, and it will bite you: the default stop of -1 means "exclude the last element", not "go to the end". In Python, my_list[:-1] gives you everything but the last item. So if you drop this node into a graph expecting a "give me the whole tail" behavior, you'll silently lose the final element. To slice through the very end, turn use_none_stop on - that's the only way to get a true "to the end" slice.
The step does the rest of the work. 2 takes every other element; -1 reverses the list entirely. Combined with negative start/stop, you can do the whole range of Python slicing tricks without leaving the graph.
Where you'll use it
- Taking the first N frames or images from a batch before processing.
- Dropping the last item off a list (that's what the
-1default actually is). - Reversing a list for "play backwards" effects or reordering.
- Decimating a long list for quick previews - every 4th item instead of all of them.
Output is slice, typed *, so the result is the same kind of list as the input - chain it into YogurtListJoin, YogurtListLength, or another slice.
Install
ComfyUI Manager, search ComfyUI-YogurtNodes, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes
cd ComfyUI-YogurtNodes
pip install -r requirements.txt
Restart, look under "Yogurt Nodes". Light dependencies, no model downloads - the only thing to study here is the stop-value semantics above, not your install log.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| list_data | * | 任何支持切片操作的列表类型对象 | |
| startopt | INT | 0-2147483648–2147483647 | 起始索引(包含)。None表示从开头开始 |
| stopopt | INT | -1-2147483648–2147483647 | 结束索引(不包含)。None表示到结尾 |
| stepopt | INT | 1-2147483648–2147483647 | 步长。默认为1 |
| use_none_startopt | BOOLEAN | false | 使用None作为起始位置(从开头切片) |
| use_none_stopopt | BOOLEAN | false | 使用None作为结束位置(切片到结尾) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| slice | * | — |