Nodes/WAS Node Suite v3/Text Dictionary Items
ComfyUI Node Runs on cloud

Text Dictionary Items

Unpick a dictionary onto parallel wires

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Text Dictionary Items
  • dictionary
  • keys
  • values
  • pairs
  • count
sortnone

Dictionaries are great for carrying a pile of named values down one wire, but they're a dead end until you can get the contents back out where loops and switches can read them. Text Dictionary Items is the node that opens the box.

What it does

Feed it a dictionary (from Text Dictionary New, Text Dictionary Update, or any node with a DICT output) and it splits the contents onto four sockets:

  • keys - the entry names, one ARRAY wire, like ['subject', 'style'].
  • values - what each name is stored against, in step with keys.
  • pairs - every entry written out as text, subject: a cat, one to a line. Great for a preview, a caption, or a saved text file.
  • count - how many entries the dictionary holds. Feed it to a For Loop's iteration count and you run the graph exactly once per entry.

The point of the design is that keys and values line up. Entry 0 of one belongs with entry 0 of the other, so a For Loop stepping one index through both reads a key and its value together - the dictionary becomes a batch of pairs your graph can iterate over. On top of that, a value that itself holds several alternatives stays a list on the wire, so ['a cat', 'a wolf'] arrives whole rather than flattened into text.

The one control

sort orders both lists together, and the default none keeps the order entries were added in. If you want them alphabetical, key sorts A–Z by name and value by the value-as-text. Two quirks worth knowing: case is ignored (Apple sits beside apple), and digits sort as text rather than numerically - so '10' comes before '9'. If your keys are numbered and you need numeric order, sort them yourself before building the dictionary.

What it pairs with

The intended companion is Text List Get plus a loop index to pull one key and one value per iteration, or Text List Length to check the count without building a loop. And if you only want the names - not the values - Text Dictionary Keys gives you the key list on its own, which is the lighter-weight route when that's all you need.

Honestly, for a lot of workflows this node is the answer to "I built a dictionary, now how do I actually use it?" The pairs text output is also quietly useful for logging: dump the whole dictionary to Text to Console or a text file and you've got a readable record of what a run was configured with.

Installing it

Part of WAS Node Suite v3 (WASasquatch's was-node-suite-comfyui, MIT). Search "WAS Node Suite v3" in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git

Restart ComfyUI after cloning. Requires ComfyUI 0.14.0+ and Python 3.10+; no extra dependencies.

CategoryWAS Suite/Text/Dictionary

Inputs (2)

NameTypeDefaultDescription
dictionaryDICTThe dictionary whose entries are wanted, keys and values both.
sortCOMBOnoneOrder both lists come out in. `none` = the order the entries were added; `key` = A to Z by name; `value` = A to Z by the value as text. Case is ignored, so 'Apple' sits beside 'apple', and digits sort as text: '10' before '9'.

Outputs (4)

NameTypeDescription
keysARRAYThe entry names on one wire, such as ['subject', 'style']. Feed it to Text List Get with a For Loop's index to read one name per iteration.
valuesARRAYWhat each name is stored against, in step with keys. An entry holding several alternatives stays a list, so ['a cat', 'a wolf'] arrives whole rather than as writing.
pairsSTRINGEvery entry written as `subject: a cat`, one to a line. For a preview, a caption or a saved text file. A value carrying line breaks of its own spans several lines. An empty dictionary gives an empty string.
countINTHow many entries the dictionary holds, 0 when it holds none. Feed it to a For Loop's iteration count to run the graph once per entry.