Nodes/comfy-ovum/_.findKey
ComfyUI Node

_.findKey

Find the key, not the value

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.findKey
  • py_dict
  • predicate
  • *
predicate_json

_.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 ANY input.
  • 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 like 30, or true - 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.

Categoryovum/underscore

Inputs (3)

NameTypeDefaultDescription
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_jsonoptSTRINGpredicate_json: JSON or key selector. Used when 'predicate' input is not connected.

Outputs (1)

NameTypeDescription
**