ComfyUI Node

List Filter

Filter a list by what its strings contain

By DebugPadawan·Created about a year ago·Updated 5 months ago· 2
List Filter
  • input_list
  • filtered_list
  • count
filter_mode
filter_value
excludefalse

A list of 200 tags where you only want the ones about hair. A prompt list where everything ending in .png has to go. A pile of filenames where only the night_ set matters. List Filter is the sieve: keep the items whose string form matches a rule, drop the rest, and get a count of what survived. It's the pack's workhorse for "I have too much list and I want less of it."

It's part of DebugPadawan's ComfyUI Essentials, a small MIT-licensed utility pack with a full family of list nodes.

How it works

Every item in the list gets coerced to a string (str(item)), then tested against filter_value using whatever filter_mode you picked:

  • contains - the value is a substring of the item.
  • starts_with / ends_with - prefix/suffix matching.
  • equals - exact string equality.
  • regex - Python re.search against the value; the pattern lives in filter_value.

There's also an exclude boolean (default false). Flip it and the logic inverts: keep everything that does not match. That's how "keep only hair tags" becomes "drop all hair tags" without changing the mode.

The gotchas

  • Matching is always against the string form. Numbers, images, anything - they all get stringified before the test. That's fine for tags and filenames, surprising if you expected numeric comparison. This node does string filtering, not range filtering.
  • Regex failures fail silently. A malformed pattern doesn't crash the node; it's caught and treated as "no match," so you get an empty (or fully excluded) list with no error. If the output looks wrong, check your pattern - invalid regex gives you nothing, not a hint.
  • equals is exact and case-sensitive. "Hair" won't match "hair". There's no case-insensitive mode; pre-normalize with a case node if you need it.

Inputs and outputs

  • input_list - the LIST to filter.
  • filter_mode - the five modes above.
  • filter_value - the string to test against (default empty).
  • exclude - invert the match (optional, default false).

Outputs: filtered_list (LIST) and count (INT - how many survived, which is your quick sanity check).

Install

Standard custom-node fare:

cd ComfyUI/custom_nodes
git clone https://github.com/DebugPadawan/DebugPadawans-ComfyUI-Essentials.git

Restart ComfyUI, or install via ComfyUI Manager by searching "DebugPadawan". requirements.txt lists numpy, torch, and opencv-python - numpy and torch already ship with ComfyUI and the shipped code never imports cv2, so no heavy downloads, no model files, no API keys.

Where it earns its keep

Clean a merged tag list before it hits a prompt builder, strip unwanted items after a list merge, or use regex to extract only entries containing digits (say, \d). Pair it with the pack's List Info to confirm you got the size you expected - count should match your mental math.

CategoryDebugPadawan/List

Inputs (4)

NameTypeDefaultDescription
input_listLIST
filter_modeCOMBO5 options: contains, starts_with, ends_with, regex, equals
filter_valueSTRING
excludeoptBOOLEANfalse

Outputs (2)

NameTypeDescription
filtered_listLIST
countINT