_.findKey
Find the key, not the value
- py_dict
- predicate
- *
_.find searches a list. _.findKey searches an object and hands back the key where your truth test passes - not the value. Feed it {"seed": 1, "steps": 30, "cfg": 7} and a predicate that matches 30, and you get back the string "steps". No match returns None (the docs say "undefined"; in the Python port you get None).
It's one of the _.* nodes in sfinktah/comfy-ovum, the author's grab-bag pack, generated as a thin wrapper around underscore3 (a Python port of Underscore.js). Every node in the family shares the same skeleton; this is the object-oriented one, so its primary input is named py_dict to signal it expects a dictionary.
When it's actually worth it
Honestly? Niche. The realistic ComfyUI use case is when you're carrying around a Python dict - say a config block or a metadata map - and you need to know which key holds a particular value, because downstream logic keys off the name. Pair the returned key with _.get to then pull the value back out, or with a string node to build a label. If your values are unique, this is a cheap way to do a reverse lookup without writing {v: k for k, v in d.items()} in a Python node.
The inputs that matter
- py_dict - the dictionary to search (loose
*input; also accepts a_.CHAIN). - predicate - the truth test, as an
ANYinput. - predicate_json - the one you'll type in when nothing's wired to
predicate: JSON or a plain selector. Because this works over values, you'll mostly put a JSON literal here - a number like30, ortrue- or a callable if you have one.
Output is a loose *: the matching key (a string, usually), or None.
Install
ComfyUI Manager, search "comfy-ovum", or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart and it's under ovum/underscore. Nothing to download.
Honest warnings
Two things. First, the family-wide disclaimer from the README: work in progress, "an absolute disaster to use in production." Second, remember this searches values and returns keys - if you actually wanted the value back, _.find on list_or_dict or a plain _.get is the better tool. And if you feed in a _.CHAIN you get a chain out; run _.value to unwrap it.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| py_dictopt | * | Primary input object (expected object). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining. | |
| predicateopt | * | predicate: ANY input to override widget. Accepts function, key string, or object shorthand. | |
| predicate_jsonopt | STRING | predicate_json: JSON or key selector. Used when 'predicate' input is not connected. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |