Nodes/comfy-ovum/_.compact
ComfyUI Node

_.compact

Quietly delete the junk from a list

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.compact
  • py_list
  • LIST

_.compact is the "clean the list up" node. It takes a list, drops every falsy value, and hands you back only the elements worth keeping. In a Comfy graph that's the thing you sprinkle between a messy upstream and a downstream node that chokes on empty strings or None - list concatenations that leave None in the middle, wildcard expansions that produce blank entries, conditionals that pass through empty values. One _.compact and the noise is gone.

The author's description spells out what counts as falsy, in JavaScript terms: false, null, 0, "", undefined and NaN. Since this is a Python port, the practical translation is None, False, 0, and empty strings. If a list element is any of those, it's out.

How it works

Like the rest of the ovum/underscore family, _.compact is a generated wrapper around underscore3, the bundled Python port of Underscore.js. It returns a copy of the list with falsy values removed - the input isn't mutated, which matters in Comfy because nodes can be re-run against cached state. The output keeps the same order as the input, just with holes removed.

One Python-vs-JavaScript nuance worth knowing: an empty list is truthy in Python, so [] survives _.compact. If your pipeline generates empty sub-lists and you want those gone too, you'd want to filter on "list is empty" rather than rely on compact's falsy check.

Inputs and output

  • py_list (any type) - the list to clean. Accepts a _.CHAIN if you're mid-chain.
  • Output: LIST - the cleaned copy.

That's the whole surface area. No widgets, no options, nothing to mis-set. This is about as close to a "do one thing" node as the family gets.

Installing it

Part of sfinktah/comfy-ovum ("comfy-ovum"):

  • ComfyUI Manager: search "comfy-ovum", install, restart.
  • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/sfinktah/comfy-ovum, restart.

No model files, light Python requirements, underscore3 bundled in the repo.

When it earns its keep

The classic use is guarding a text-to-prompt or batch pipeline: a list of raw lines that may contain blanks, fed through _.compact before a List Slice or a batch node. It's also handy right before a conditional that counts items - a size check on the compacted list is far more meaningful than on the raw one. Keep in mind the author marks the underscore suite as work-in-progress in the README, but _.compact is simple enough that the risk is mostly theoretical.

Categoryovum/underscore

Inputs (1)

NameTypeDefaultDescription
py_listopt*Primary input object (expected array). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining.

Outputs (1)

NameTypeDescription
LISTLIST