_.pairs
Flatten a Dictionary Into [key, value] Pairs
- py_dict
- LIST
_.pairs takes a dict and hands you back a list of [key, value] lists: {"width": 1024, "height": 576} becomes [["width", 1024], ["height", 576]]. It's the exact reverse of _.object, and it exists because a lot of ComfyUI's logic and list utilities are much happier iterating over a flat list than reaching into a dict by name.
Why you'd want a list of pairs
ComfyUI's LIST type is the lingua franca of every list-manipulation pack - slice it, loop it, concat it, feed it to an iterator. Dicts, by comparison, are something you can only poke at through a handful of dedicated nodes. So when a metadata dict needs to flow through list-oriented tools, _.pairs is the bridge: every entry becomes a two-element list, and any list-iterate node can now walk your whole object.
Concrete example: you've got a dict of settings, and you want to render each one as a line of text - key: value for every entry. Pluck-style nodes can't iterate a dict for you, but a LIST of pairs can be mapped over cleanly. It's also a handy diagnostic: feed a dict in, get a readable list you can inspect.
The interface is nearly empty:
py_dict- the dictionary (or a_.CHAIN)
Output: a LIST of [key, value] pairs.
How it works
It walks the dict's keys in order and builds the pair list. Keep in mind the standard Python ordering caveat: dicts preserve insertion order, so the pairs come out in the order the keys were added - don't assume alphabetical or sorted unless you sort downstream. The input is deep-copied before anything happens, so nothing upstream gets mutated.
The round trip
_.pairs and _.object are inverses: pairs → object rebuilds the dict, object → pairs flattens it back. That round trip is a genuinely useful pattern when you need to rearrange data through list-land and then restore the dict shape afterward. Just be aware that if your keys aren't all the same type or you have duplicate keys in the pair list, the dict you rebuild may differ from the one you started with.
Installing
Part of comfy-ovum. ComfyUI Manager → search comfy-ovum → Install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart ComfyUI. No models, no extra pip packages for the underscore nodes - the underscore.js port is bundled in the repo.
The bottom line
The standard way to make a dict work with list-oriented tools: flatten it to [key, value] pairs, do your list stuff, and use _.object to build it back if you need to.
Inputs (1)
| 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. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LIST | LIST | — |