_.last
Grab the last item in a list — and mind the n-elements twist.
- py_list
- *
The last item in a list is something you actually need in Comfy: the final frame of a batch, the newest filename in a list, the last seed generated. _.last gets it for you with one input and zero ceremony. The only wrinkle is the n parameter, and it's a wrinkle that has bitten more than a few people.
What it is
Part of the ovum/underscore family in sfinktah/comfy-ovum, wrapping the last method of underscore3, a Python port of Underscore.js. No iteratee, no shorthand, no cleverness: return the last element, or the last n elements.
Inputs and outputs
py_list(type*) - the list. The generator names array-ish inputspy_list; any JSON-serializable value works.n(INT, default1) - how many elements to take from the tail.
Output is one value, typed * (ANY). Feed a _.CHAIN and you get a chain back for continued chaining, resolved with _.value.
The trap in n
Default n=1 returns the last element itself - a scalar. But set n to anything, including 1, and you get a list of the last n elements. Yes, n=1 is different from the default of 1. That's faithful to Underscore.js semantics, and the port's own docs call it out, but it still catches people: they set n=1 thinking they're being explicit, and suddenly their scalar input is a one-element list and a strict node downstream throws a fit. If you want a single element, leave n alone. If you want a slice of the tail, set n - and expect a list.
Where it earns its place
Batch tails, mostly. Last frame in a video batch, last item after a sort, the newest of a set of paths. Pair it with _.max-style logic and you can grab the "winning" element after ranking. It's small, but it removes a whole class of "index from the end" arithmetic that Python makes awkward without negative indexing.
Installing comfy-ovum
ComfyUI Manager: search for comfy-ovum, install, restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
pip install -r comfy-ovum/requirements.txt
Restart and you're done. No model downloads, no CUDA - pure-Python utilities. Family caveat: the README calls these nodes a work in progress. _.last is low-risk in practice; just keep that n quirk in mind and you're fine.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| py_listopt | * | Primary input object (expected array). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining. | |
| nopt | INT | 1 | n (int) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |