union

Command in the TclX package to return the logical union of the two specified lists. Any duplicate elements are removed.

Usage:

union lista listb

Example:

  package require Tclx
  union {a b c d e} {d e d f g c} ;# ==> a b c d e f g

Note that duplicate elements are removed and the resulting list is sorted.


This functionality exists in tcllib in the struct::set package.


I believe this can also be implemented in Tcl without an extension via:

proc union {a b} {
    lsort -unique [concat $a $b]
}