ComfyUI Node

count

Count — how many times does that value actually show up?

By StableLlama·Created about a year ago·Updated 4 days ago· 48
count
  • list
  • value
  • count

count answers "how many times does this value appear in the LIST?" and hands you back an integer. It's the "yes/no, but with numbers" version of contains - instead of "is it in there?" you get "how often?" That distinction is exactly what you want when you're tracking duplicates, tallying results across a batch, or checking that nothing got processed twice.

How it works

It's a straight wrapper around Python's list.count():

return (list.count(value),)

value accepts any type (*), and matching is exact equality, same rules as contains: 1 and 1.0 compare equal in Python, but a string "1" will never match a numeric 1. Counting is full-scan, so for big lists it's O(n) per call - irrelevant for the handfuls of items you'll normally deal with in a workflow.

The output is an INT named count. It returns 0 for a value that isn't present, which means you can use it as a membership test too - just remember that 0 is falsy if you route it into boolean logic.

Where you'd use it

  • Duplicate detection. Count a seed or filename; if the count is more than one, you've got a repeat you probably didn't want.
  • Batch tallying. "How many frames failed the check?" - build a LIST of booleans and count False.
  • Frequency checks. Count how many times a specific tag or keyword shows up in a LIST of strings before deciding something.
  • Quality gates. Combine with >= or <= from the same pack: "if failures > 0, stop."

Installing

It's in 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. No dependencies, no model files - the pack is pure Python with zero declared requirements, so this is one of the lowest-friction installs in the ecosystem.

Gotchas worth knowing

  • A missing value counts as 0, not an error - that's usually convenient, but it's why count and contains overlap in coverage. contains is clearer when you only want the boolean.
  • Exact-equality matching: whitespace, case, and type all count. "Video" and " video" are different.
  • Works on the pack's LIST type, not a native ComfyUI data list. If you're holding a data list, convert it to LIST first.
CategoryBasic/LIST

Inputs (2)

NameTypeDefaultDescription
listLIST
value*

Outputs (1)

NameTypeDescription
countINT