ComfyUI Node

_.chunk

Slice one big list into batches of N

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.chunk
  • py_list
  • LIST
length1

_.chunk is the node you reach for when you have one long list and you want it broken into same-size groups. Feed it a list of 30 filenames and a length of 10, and you get back three lists of ten. That pattern shows up all over Comfy workflows: batching prompts, splitting a batch of images for tile-by-tile processing, or grouping a list of seeds so each group flows into a different branch.

The author's description nails it: "Chunks an array into multiple arrays, each containing length or fewer items." The last chunk gets whatever's left over, so uneven division is fine.

How it works

Like every node in the ovum/underscore family, _.chunk is a generated wrapper around underscore3, the Python port of Underscore.js that ships inside the comfy-ovum pack. It maps directly to the JavaScript _.chunk semantics, which the port mirrors faithfully:

  • chunk([1, 2, 3, 4, 5, 6, 7], 2)[[1, 2], [3, 4], [5, 6], [7]]
  • chunk([1, 2, 3], 1)[[1], [2], [3]]

The input list is not mutated - you get a fresh list of lists out.

Inputs and output

Two inputs:

  • py_list (any type) - the list to chunk. You can also feed it a _.CHAIN to keep a chain going, since the whole family interops.
  • length (INT, default 1) - items per chunk. Set it to your batch size.

Output is a single LIST. Important gotcha: the output is a list of lists. Each element of the output is itself a batch. If you then feed this straight into a node expecting a flat list of items, it will treat each whole chunk as one item - which is often exactly wrong. Either keep the batches as groups deliberately, or flatten downstream before doing item-by-item work.

Installing it

Part of sfinktah/comfy-ovum ("comfy-ovum"). One install covers the whole underscore family:

  • ComfyUI Manager: search "comfy-ovum", install, restart.
  • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/sfinktah/comfy-ovum, restart.

Light dependencies (pillow, numpy, requests…), no model downloads. underscore3 is bundled in the repo.

Where people trip up

The most common mistake is forgetting the output is nested - checking "list" and getting a list-of-lists, then wondering why downstream gets garbage. Second: if you leave length at its default of 1, every item becomes its own chunk, so you get a useless copy of the input. Set the length before you wire anything else. One more honest note: the author flags the whole underscore suite as work-in-progress in the README, so treat _.chunk as handy plumbing, not as infrastructure for a production pipeline.

Categoryovum/underscore

Inputs (2)

NameTypeDefaultDescription
py_listopt*Primary input object (expected array). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining.
lengthoptINT1length (int)

Outputs (1)

NameTypeDescription
LISTLIST