ListLength (Yogurt Nodes)
Count what you've got before you loop over it
- list_data
- length
The single most useful number in a ComfyUI workflow is often the one nobody bothers to calculate: how many things are actually in this list? YogurtListLength answers that. It takes any list-like object and returns its length as an INT. That's it - one input, one output, and an enormous amount of utility hiding in the simplicity.
It comes from ComfyUI-YogurtNodes, the 150+ node grab-bag by yogurt7771. The pack is the definition of obscure - MIT-licensed, auto-generated README, essentially zero community footprint - but its logic section is a toolbox of exactly these "why doesn't ComfyUI already do this" helpers, and Length is the one you'll reach for constantly once you know it exists.
How it works
The mechanism is Python's len(), exposed as a node. list_data is typed * so it accepts any iterable that supports len() - a list of prompts, a batch of images, a list of filenames from YogurtGlobFiles, a split string. The length INT output is the count.
Where it earns its keep is in anything conditional or iterative. ComfyUI has no built-in "count my batch" node, so people hardcode numbers and then wonder why a workflow breaks when the batch size changes. This node makes the number a real value that can drive other logic.
Where you'll actually use it
- Loop control: generate a
YogurtRange(0, length)and iterate over exactly as many items as exist. - Sanity checks: compare the length against what you expected, then use the comparison to switch behavior.
- Guard rails: before
YogurtListIndexon an unknown-length list, checking the length first prevents the out-of-range error that would kill the whole graph. - Splitting decisions: if a list is longer than N, process it in chunks; if shorter, handle it whole.
The output is a plain INT, so it feeds anything numeric - a YogurtRange, a Switch, a comparison node, a text formatter for a debug readout.
There's not much to get wrong with this one, which is the point. The only real gotcha is the same as its sibling nodes: it expects an actual list-like object, so feed it one output rather than an unconverted string. If you're ever unsure whether the thing upstream of you is a list, this node will tell you immediately by erroring - or, well, by counting.
Install
ComfyUI Manager, search ComfyUI-YogurtNodes, install, restart. Or clone:
cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes
cd ComfyUI-YogurtNodes
pip install -r requirements.txt
Restart and it's under "Yogurt Nodes". Light dependencies, no model downloads - this pack's logic nodes are pure Python, so installation is as painless as ComfyUI installations get.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| list_data | * | 任何支持len()函数的列表类型对象 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| length | INT | — |