ComfyUI Node

length

How big is that list? Ask instead of guessing

By StableLlama·Created about a year ago·Updated 4 days ago· 48
length
  • list
  • length

Most of the time you don't care how many items are in a list. Then one day your workflow depends on it - "only run the detail pass if there are more than three candidates," "loop exactly this many times," "bail out if the batch came back empty" - and you realize ComfyUI has no obvious way to ask. DataListLength is the answer: one input, one INT output, done.

The input is list (any type you throw at it) and the output is length, a plain integer. It's len() from Python exposed as a node, nothing more, nothing less. Because the input is marked INPUT_IS_LIST, ComfyUI hands the node the whole collection and it counts every item in one pass.

Why you'll actually reach for it

The killer use is gating. Length feeds beautifully into this pack's comparison nodes (greater than, less than, equal) and its control-flow nodes (if/else, switch). That turns "the batch came back with nothing" from a silent failure into a decision point: if length == 0, route to an error path or a fallback; if it's over a threshold, take the expensive branch.

It's also handy for sanity checks while you build. Wire a list into length, add a text display node, and you can watch live whether a filter, slice, or pop node is actually producing the number of items you expected. That's the debugging workflow that catches most data-handling mistakes before they turn into garbage output.

How it works

The node is a straight len(kwargs.get('list', [])). Empty list gives you 0 - no special-casing needed, no errors, which is exactly what you want from a measurement node. The output is a real INT, so it plugs into any integer input across the pack or any other node pack that takes an INT.

Installing it

Part of StableLlama's Basic data handling pack, a pure-Python collection with no dependencies and no model files. One install covers this and 250+ sibling nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Or just search "Basic data handling" in ComfyUI Manager and install it there. Either way, restart ComfyUI afterward. There's no requirements.txt drama because there are no third-party dependencies - the pack runs entirely on the standard library.

Common issues

The only thing that bites is the same type confusion that runs through the whole pack: this measures a data list, not a single LIST variable. If your upstream node emits LIST (a Python list passed around as one value) and you feed it here, you'll get a type error or a length of one - the node may treat the whole LIST as a single element. When in doubt, check whether your source node's output port says * (a data list) or LIST/SET. If it's the latter, convert to a data list first, or use the pack's LIST-family nodes instead.

CategoryBasic/Data List

Inputs (1)

NameTypeDefaultDescription
list*

Outputs (1)

NameTypeDescription
lengthINT