Nodes/comfy-ovum/_.initial
ComfyUI Node

_.initial

Everything in the list except the last one

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

_.initial is the trim-the-end slice: give it a list and it returns everything except the last entry. Pass n and it drops the last n. If you've written my_list[:-1] in Python, you know exactly what this does - and if your workflow deals with frames, batches, or any sequence where "process all but the final item" comes up, you now have it as a node.

How it works

The implementation is almost embarrassingly short:

def initial(self, n=1):
    return self._wrap(self.obj[0:-n])

It's a Python slice - non-mutating, returns a new list, and n defaults to 1. It's the direct port of Underscore.js's _.initial, which exists because in JavaScript-land arr.slice(0, -1) is the "everything but the last" idiom and Underscore gave it a name.

Because it's a plain slice, there are no surprises: empty list in, empty list out. n larger than the list length gives you an empty list rather than an error, which is the friendly behavior you want from a utility node.

The inputs that matter

Only two:

  • py_list - the primary input (*), the list you're trimming. Also accepts a _.CHAIN to continue chaining.
  • n - an INT, default 1. How many trailing elements to drop. This one's a widget-only control per the schema's tooltip (n (int)), so you set it right on the node.

Output is a single LIST - the original list minus the last n elements, in original order.

Where you'd actually use it

The classic batch pattern: you've generated a sequence of frames or a list of steps, and the last one is special (a sentinel, a duplicate, a final frame you handle differently). _.initial gives you "all of them except that one" as a clean list to feed a loop, a batch node, or a _.each-style consumer.

It also composes with the rest of the underscore family: _.initial then _.last on the same input covers both sides of "everything but" and "just the last." And since it's non-mutating, you can chain or branch off the same source list without worrying about side effects.

Installing

Ships in comfy-ovum (MIT). ComfyUI Manager → search comfy-ovum → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

The underscore nodes run on the bundled underscore3 port - no extra install. Pack-wide requirements.txt pulls pymediainfo (which can need the system libmediainfo library on Linux), tomli-w, requests, braceexpand, pillow, numpy, markdown-it-py, and aiohttp.

Gotchas

Honestly, this one's about as safe as the pack gets - it's a slice, and slices are boring in the good way. The main caveat is the pack-level one: the README flags the entire underscore family as WIP and warns against production use. For _.initial specifically that's a loud warning for a quiet node; just don't feed it something weird like a dict and expect magic. It's for lists, it slices from the end, and it doesn't mutate.

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.
noptINT1n (int)

Outputs (1)

NameTypeDescription
LISTLIST