_.countBy
Histogram your list, no spreadsheet required
- list_or_dict
- iteratee
- DICT
_.countBy turns a list into a histogram: it groups the items and counts how many land in each group, then hands you back a dict of group → count. The author's description is the classic one: "Sorts a list into groups and returns a count for the number of objects in each group. Similar to groupBy, but instead of returning a list of values, returns a count for the number of values in that group."
In a Comfy workflow that's surprisingly useful. Have a list of model names and want to know how often each appears? A list of tags with duplicates, and you need the top tag by frequency? A batch of results you want to summarize before deciding which branch to take? That's a _.countBy away.
How it works
Generated wrapper around underscore3, the bundled Python port of Underscore.js. The grouping key comes from the iteratee. The flexible part is what an iteratee can be - the tooltip says it "accepts function, key string, or object shorthand." That's the Underscore way:
- Key string:
iteratee = "category"groups items by theircategoryattribute/key. - Object shorthand:
iteratee = '{"style": "anime"}'counts only items matching that sub-object. - Function: only if you can get a Python callable into the socket (e.g. via the pack's
PY_FUNCexports).
The iteratee_json widget is the text-box fallback: when the iteratee socket isn't connected, the node parses that widget as JSON or a key selector and uses it.
Inputs and output
list_or_dict(any type) - the collection to histogram. Accepts a_.CHAINto keep a chain going.iteratee(any type) - optional socket override; function, key string, or object shorthand.iteratee_json(STRING, multiline) - the widget you'll actually use most of the time: type a JSON object or a property name here.- Output:
DICT-{group: count}.
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 downloads; light dependencies; underscore3 bundled in the repo.
Where it bites
The iteratee behavior is the fiddly part. If you leave iteratee_json empty and nothing is connected, every item falls into a single bucket (or the port's default grouping kicks in), and you get a {value: count} of the raw values - which is fine if that's what you wanted, confusing if you expected property-based grouping. Also remember the output is a DICT, not a LIST; a downstream node expecting a list will complain. And keep the pack's standing caveat in mind: the whole underscore family is flagged as work-in-progress by the author. For a quick frequency count it's great; for anything you plan to ship in a workflow people rely on, double-check the grouping with a small list first.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| list_or_dictopt | * | Primary input object (expected collection). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining. | |
| iterateeopt | * | iteratee: ANY input to override widget. Accepts function, key string, or object shorthand. | |
| iteratee_jsonopt | STRING | iteratee_json: JSON or key selector. Used when 'iteratee' input is not connected. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| DICT | DICT | — |