Nodes/WAS Node Suite v3/Text List Slice
ComfyUI Node Runs on cloud

Text List Slice

Cut a range out of a list, both ends included

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Text List Slice
  • text_list
  • ARRAY
  • strings
  • count
start0
end-1
step1

Need lines 10 through 20 of a prompt file? Every third tag out of a split? Text List Slice is the pack's answer to Python's list[9:19] - with one crucial difference that will bite you if you assume it behaves identically.

What it does

Give it a list plus a start and an end, and it takes every entry from start to end - with both ends included. That's the trap. Python slices exclude the end, so people instinctively read "start 9, end 19" as ten entries. Here, start 9 and end 19 gives you eleven: the 10th through the 20th. Both positions are inclusive, full stop.

The defaults are set up for the common case of "from here to the end." start defaults to 0 and end to -1, where -1 means the last entry (negative indices count from the end throughout). So with no changes, the node passes your whole list through. Set an end past the last entry and it just stops there.

The extra step input controls spacing: 1 takes every entry, 2 takes every second one starting at start, 3 every third. The last entry is only taken when the stepping happens to land on it. And a start before the beginning simply begins at the first entry - no crash.

One hard rule to respect: an end that comes before start selects nothing, and the node stops the prompt. Because the run below it is also emitted as a list, the graph underneath literally cannot run zero times - so rather than silently doing nothing, it fails loudly. If that case is possible in your data, guard it upstream.

What comes out

Three sockets, and the middle one is the reason this node exists:

  • ARRAY - the entries taken, on one wire, for feeding other list nodes like Text List Get or Text List Concatenate.
  • strings - the same entries as a STRING list. This is the list-output trick the whole suite uses: any node reading it runs once per entry and produces one result per entry. Wire it into a sampler's prompt and you render every line of a range in turn, each a separate image.
  • count - how many entries the range took, so a For Loop knows its length.

The shape to remember: this is how you turn "I want entries 5 through 15" into "render nine images, one per line." The strings output does the fan-out; everything below the node iterates.

Installing it

Part of WAS Node Suite v3 (WASasquatch's was-node-suite-comfyui, MIT). Search "WAS Node Suite v3" in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui.git

Restart ComfyUI afterward. Requires ComfyUI 0.14.0+ and Python 3.10+; no extra dependencies for this node.

CategoryWAS Suite/Text/List

Inputs (4)

NameTypeDefaultDescription
text_listARRAYThe list to take from, such as the lines output of Load Text Line or the LIST output of Text Split to List, Text List or Text Dictionary Keys.
startINT0-99999999–99999999The first entry taken, counting from 0, and it is taken. -1 is the last entry, -2 the one before it. A start before the beginning of the list begins at the first entry.
endINT-1-99999999–99999999The last entry taken, and it is taken as well: start 9 and end 19 give 11 entries, the 10th to the 20th. -1 is the last entry.
stepINT11–99999999How far to move between entries taken. 1 takes every entry, 2 takes every second one starting at start, 3 every third. The last entry is taken only when the stepping lands on it.

Outputs (3)

NameTypeDescription
ARRAYARRAYThe entries taken, on one wire, for Text List Get, Text List Concatenate and Text List to Text.
stringsSTRINGThe same entries as a STRING list. Because this is a list, a node reading it runs once per entry and produces one result per entry, wire it into a sampler's prompt to render every line of a range in turn. An entry that is not text is converted to it.
countINTHow many entries the range took.