first
First — the head of the list, without the off-by-one ceremony
- list
- first_element
first pulls the first element out of a LIST and hands it to you directly. No index, no get item, no remembering that Python starts counting at zero - it's just "give me the head of this list." When the thing you care about is the first item specifically - the first seed in a batch, the first filename, the first value in a sweep - this is the node that makes that a one-wire operation.
How it works
It's a two-line guard over Python's index access:
return (list[0] if list else None,)
Two behaviors worth internalizing. First, it returns the element itself, whatever type it is - an int, a string, a dict, anything, since the output type is *. Second, and this is the one people get surprised by: an empty list returns None, not an error. That's friendlier than raw Python, which would throw IndexError, and it means the node won't crash your graph - but it also means None can flow into whatever you're feeding, so if the list being empty is possible, decide how you want to handle that downstream.
The output is named first_element. There's no index input - you don't get to choose which element; that's get item's job. This node is deliberately single-purpose.
Where you'd use it
- Pulling one value for the next step. First seed, first prompt, first checkpoint in a list.
- Default/fallback logic. Get the first item of a list and route with
<=,==, orcontains- "if the first item isn't what I expect, bail." - Batch starts. When you process a list one at a time,
firstgives you the current head after you've popped or sliced the rest away.
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. Guard it if you can't tolerate aNonedownstream. - It returns element 0, period. For anything else,
get item(which also handles negative indices) is the more flexible tool. - Works on the pack's LIST type (single Python list variable), not a native data list.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| list | LIST | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| first_element | * | — |