ComfyUI Node

length

How many entries is that dict? — the count that feeds your logic

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

"length" returns the number of key-value pairs in a dictionary as an INT. It's len(dict) with a node around it, and it exists because dicts are opaque objects in ComfyUI - you can't just hover and see a count. When the size of a dict is something your workflow needs to react to, this is the node that turns "how big is this?" into a number you can branch on.

You'd reach for it most often in control flow: "only proceed if the dict has entries," "if this config dict has more than N settings, take the verbose path," "did the merge actually produce anything?" Feed the INT into a comparison or if/else node and the dict's size becomes a first-class condition.

How it works

  • input_dict (DICT) - the dictionary to measure.
  • Output: length (INT) - the count of entries.

An empty dict returns 0. A dict with three pairs returns 3. It's counting key-value pairs, not total characters or nested items - a value that's itself a list of twenty things still counts as one entry.

Where it fits

  • Emptiness checks: length == 0 is the cleanest "is this dict empty" test. A filtered dict that dropped everything, a from keys result that got no keys - this is how you detect that.
  • Sanity checks: after a merge or filter, verify the dict still has the size you expect before feeding it downstream.
  • Pacing logic: branch on whether a config dict has "enough" settings to matter.

The thing to keep in mind

It's a count of pairs, and pairs is all it is - don't try to infer structure from the number. A length of 1 could be {"a": 1} or {"a": [1,2,3,...]}. If you need what's inside rather than how much, pair this with keys or items. But for "should this branch even run?" questions, length is the fastest answer in the pack.

Install

Part of Basic data handling - pure Python, zero dependencies, no model downloads. ComfyUI Manager → search "Basic data handling", or:

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

then restart ComfyUI. Simple node, and the natural partner to the pack's comparison and control-flow sections for dict-aware logic.

CategoryBasic/DICT

Inputs (1)

NameTypeDefaultDescription
input_dictDICT

Outputs (1)

NameTypeDescription
lengthINT