Nodes/ComfyUI-YogurtNodes/ListSlice (Yogurt Nodes)
ComfyUI Node

ListSlice (Yogurt Nodes)

Slice a list the Python way — mind the stop value

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
ListSlice (Yogurt Nodes)
  • list_data
  • slice
start0
stop-1
step1
use_none_startfalse
use_none_stopfalse

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 -1 default 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.

CategoryYogurtNodes/Logic

Inputs (6)

NameTypeDefaultDescription
list_data*任何支持切片操作的列表类型对象
startoptINT0-2147483648–2147483647起始索引(包含)。None表示从开头开始
stopoptINT-1-2147483648–2147483647结束索引(不包含)。None表示到结尾
stepoptINT1-2147483648–2147483647步长。默认为1
use_none_startoptBOOLEANfalse使用None作为起始位置(从开头切片)
use_none_stopoptBOOLEANfalse使用None作为结束位置(切片到结尾)

Outputs (1)

NameTypeDescription
slice*