ComfyUI Node

last

Last — the tail of the list, when the end is what matters

By StableLlama·Created about a year ago·Updated about 15 hours ago· 48
last
  • list
  • last_element

last grabs the final element of a LIST and hands it to you. No get item, no needing to know the length, no counting - it's the tail of the list, the counterpart to first. When the thing you care about is the most recent value - the last seed used, the last prompt appended, the final entry in a running collection - this node is the one-wire answer.

How it works

It's the first node's mirror, using Python's -1 indexing:

return (list[-1] if list else None,)

Returns the element itself, whatever type it is (* output), and - same as first - an empty list returns None instead of erroring. Raw Python would throw IndexError on list[-1] of an empty list; here you get None and the graph keeps running. That's forgiving, but it also means an empty list can quietly push None into whatever comes next. If emptiness is a real possibility, guard it.

The output is named last_element. There's no index input and no way to pick "second-to-last" - for that, you want get item with a negative index.

Where you'd use it

  • Latest value. The most recent seed, filename, or prompt in a collection you've been building with append.
  • Queue-style logic. After you append new work to a list, last is the item you just added.
  • Batch tails. "What was the final result of this sweep?" without tracking position anywhere.

Installing

Part of the "Basic data handling" pack by StableLlama. ComfyUI Manager: search "Basic data handling", install, restart. Or:

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

Restart ComfyUI. Zero dependencies, no models - pure Python, a textbook low-friction install.

Gotchas worth knowing

  • Empty list → None, not an error. Handle the empty case explicitly if you can't tolerate None.
  • It only gives you the very last element. Second-to-last is get item with index = -2.
  • Works on the pack's LIST type (single Python list variable), not a native data list - same rule as the rest of the pack.
CategoryBasic/LIST

Inputs (1)

NameTypeDefaultDescription
listLIST

Outputs (1)

NameTypeDescription
last_element*