Text List Length
Count your list before you loop over it
- text_list
- NUMBER
- length
- length_float
- is_empty
The most boring node you'll ever be glad you added. Text List Length does one thing - counts the entries in a list - but it hands the count out in every shape a workflow might want, plus a flag that keeps you from running a loop on nothing.
What it does
Drop any list into text_list (the ARRAY output of Text Split to List, Text List, Text Dictionary Keys, even Image Color Palette) and you get the count back four ways:
- NUMBER - for any node that takes a NUMBER, or as an index bound.
- length - the same count as an INT.
- length_float - as a FLOAT, which saves you a conversion node when you're computing a progress fraction like
index / length. - is_empty - a BOOLEAN, true when the list holds nothing.
Four sockets for one number might look like overkill, but it's the classic "no conversion node in between" move this pack is built around - the length of a list is one of those numbers that turns up everywhere, and you never want to stop to convert types mid-graph.
Why is_empty earns its keep
An empty list is a workflow killer: feed a zero count into a For Loop or a range and your graph either runs zero times or errors. is_empty is the guard against that. Wire it into a switch and route around whatever would fail on an empty list - fall back to a default prompt list, skip the per-entry pass, take a different branch entirely. It turns "nothing came out of the split" from a crash into a handled case.
In practice you reach for this node in two spots:
- Just above a For Loop, feeding its iteration count, so the loop runs exactly as many times as there are entries. That's the whole point of the NUMBER output.
- As a sanity check on anything that produces a list dynamically - a directory listing, a file's lines, a split of user text - before the graph commits to looping over it.
The catch is only that it's limited
That's genuinely it - one input, four outputs, no knobs. If you need to read one entry out of the list rather than count it, that's Text List Get. If you need a run of entries, Text List Slice. Length is the "how many" node, and trying to make it do anything else will just confuse you. Keep it where it belongs and it's a perfectly forgettable, perfectly reliable piece of plumbing.
Installing it
Part of WAS Node Suite v3 (WASasquatch's was-node-suite-comfyui, MIT). Search "WAS Node Suite v3" in ComfyUI Manager, or:
cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git
Restart ComfyUI after installing. Requires ComfyUI 0.14.0+ and Python 3.10+; no extra packages needed.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| text_list | ARRAY | The list to count, such as the LIST output of Text Split to List, Text List, Text Dictionary Keys or Image Color Palette. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| NUMBER | NUMBER | The entry count, for any node taking a NUMBER, Number Operation, or the index of Text List Get. |
| length | INT | The same count as a whole number. |
| length_float | FLOAT | The same count as a decimal, for the division a progress fraction needs without a conversion node in between. |
| is_empty | BOOLEAN | True when the list holds nothing. Wire it into a switch to route around the nodes that would fail on an empty list. |