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

DictLength (Yogurt Nodes)

How many keys are in this dict? An integer, instantly

By yogurt7771·Created 2 years ago·Updated 9 days ago· 1
DictLength (Yogurt Nodes)
  • dict_data
  • length

DictLength does one thing: it counts the keys in a dictionary and hands you the number as an integer. {"a": 1, "b": 2, "c": 3}3. It's the dictionary-specific cousin of the pack's DataSize node, and it's the number you want when a dict's shape matters more than its contents.

Where does a key count actually matter in a workflow? Mostly in validation and branching. You parsed a JSON payload and want to confirm it isn't empty before processing - DictLength == 0 is your "empty" test. You're expecting a config dict to have exactly the fields you need and want to warn or branch if it comes back short. You're looping over a set of named results and need the count to size a batch. In every case, a single integer feeds straight into a Switch, a compare node, or a conditional - no list inspection required.

How it works

len(dict_data) - Python's built-in, which counts the number of key-value pairs. It's not recursive (nested dicts inside values count as one value), and it doesn't deep-count anything. If that's what you expected from "size of the dict," you're set; if you wanted a flattened total, that's a job for the pack's JSON flattening tools instead.

Input & output

  • dict_data - any dict-like object supporting len().
  • length - the integer count of keys.

Install

Part of ComfyUI-YogurtNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/yogurt7771/ComfyUI-YogurtNodes.git
cd ComfyUI-YogurtNodes
pip install -r requirements.txt

Or search "YogurtNodes" in ComfyUI Manager and restart. Under "Yogurt Nodes" → Logic.

Common issues

  • "It counts nested dicts as 1" - correct behavior. Top-level keys only.
  • "I want the length of a list, not a dict" - that's YogurtListLength in the same pack.
  • "It's the wrong number" - double-check you're feeding a dict and not something dict-like that behaves differently (some wrappers report a different length).

It's a one-liner dressed as a node, but validation logic is full of "is this empty / is this the right size" questions, and this is the cleanest way to answer them. Use it right before branching on dict data and you'll save yourself a lot of silent-mismatch debugging.

CategoryYogurtNodes/Logic

Inputs (1)

NameTypeDefaultDescription
dict_data*Any dict-like object that supports len()

Outputs (1)

NameTypeDescription
lengthINT