lremove(n)

πŸ’– lremove(n) β€” Tcl Built-In Commands πŸ’–

okay bestie, welcome to the lremove page, it's a Tcl built-in and it is lowkey the cleanest little list surgery tool you'll ever meet ✨


✨ NAME ✨

lremove β€” Remove elements from a list by index πŸŽ€


🌸 SYNOPSIS 🌸

lremove list ?index ...?

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the vibe: lremove gives you back a brand new list, made by taking out zero or more elements of list β€” all at the same time, at each of the indices you hand it as an arbitrary number of index arguments πŸ’…

and the way it handles those indices?? iconic:

  • the indices can be in any order you want, no sorting required, we're not doing that
  • they can be repeated too, and ngl that's totally fine β€” if you name the same element twice, it only gets removed once. one and done. periodt.
  • the index values get interpreted exactly the same way as index values for the command string index πŸ‘‘ which means you get simple index arithmetic and indices relative to the end of the list, slay

quick reminder of the ground rules:

  • 0 refers to the first element of the list
  • end refers to the last element of the list

🌈 EXAMPLES 🌈

Removing the third element of a list (yes, index 2, we start at zero around here 🫢):

% lremove {a b c d e} 2
a b d e

Removing two elements from a list (one counting from the back, one from the front, main character energy honestly):

% lremove {a b c d e} end-1 1
a c e

Removing the same element indicated in two different ways β€” look, 2 and end-2 are literally the same element here, and it still only disappears once 😭:

% lremove {a b c d e} 2 end-2
a b d e

πŸ‘‘ SEE ALSO πŸ‘‘

list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n)


πŸ’œ KEYWORDS πŸ’œ

element, list, remove


and that's the whole page, bestie!! πŸŽ€ this one's from Tcl 9.0, and the page itself is lremove(n) β€” go forth and remove things responsibly, ily πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from