ComfyUI Node

last

Last item in the list, minus the off-by-one panic

By StableLlama·Created about a year ago·Updated 4 days ago· 48
last
  • list
  • last_element

Every once in a while you need just the last thing in a list. The last prompt in a series of scheduled prompts, the last seed in a batch, the last frame before you do something different with it. That's the whole job of DataListLast, and it does it in a way you don't have to think about.

It takes one input, list, and hands you back last_element. That's it. One wire in, one wire out. If the list has five items you get item five. If it has one item you get that item. If it's empty you get None rather than an error - which is a small but real design kindness, because it means you can chain this into a workflow and let a later node decide what to do with nothing instead of hard-crashing mid-run.

How it works

Under the hood it's just Python's list[-1], with an empty-list guard. The node is marked INPUT_IS_LIST, which is ComfyUI-ese for "give me the whole collection as a single Python list," and it returns the one element as a normal (non-list) value. So whatever type your list holds - strings, ints, floats, even images - comes out the far side with its type intact.

The one thing that trips people up is expecting last_element to still be a list. It isn't. If you need the last three items as a list, this isn't your node - that's slice with a negative start, or grab the list and trim it yourself. DataListLast gives you a single element and nothing else.

Where it fits

The natural companion is DataListLength or the pack's comparison nodes: check the list isn't empty first, then pull the last item. It also plays nicely with the pack's DataList creation and shuffle nodes - shuffle a batch, take the last one, and you've got a quick "pick one at random-ish" trick, though pop random is the more honest tool for that.

Installing it

This is one of 250+ nodes in StableLlama's Basic data handling pack. The whole pack is pure Python with zero dependencies - no models, no pip installs, nothing heavy to babysit. Install it once and every node in it appears in the menu.

Easiest path: open ComfyUI Manager, search for "Basic data handling", hit install, restart ComfyUI. Manually it's the usual two lines:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Then restart (or hit Refresh in the UI). Since the pack has no requirements.txt worth worrying about, you don't get the dependency-conflict roulette that other custom-node packs drag in - it only ever touches Python's standard library.

Common issues

There's basically one failure mode, and it's a data-type confusion rather than a bug: this node works on a data list (ComfyUI's native list where each item is processed individually), not on a single LIST variable. If you feed it a LIST object straight from a node that outputs LIST, the types won't match. Route it through the pack's "convert to LIST"/"convert to data list" converters first and you're fine. Once you've got the right collection type, last is as boring and reliable as it looks.

CategoryBasic/Data List

Inputs (1)

NameTypeDefaultDescription
list*

Outputs (1)

NameTypeDescription
last_element*