if 0 {[Richard Suchenwirth] 2004-08-27 - In the [Tcl chatroom], James Salsman discussed an extension to [lsort] which returns a list of indices in sorted order. This will go into a TIP, but for now here's a pure-Tcl implementation as proposed by James: } proc lsort-indices list { set i -1 set tmp {} foreach e $list {lappend tmp [list [incr i] $e]} set res {} foreach e [lsort -index 1 $tmp] {lappend res [lindex $e 0]} set res } if 0 {Testing: % lsort-indices {c b a} 2 1 0 % lsort-indices {} % lsort-indices {a a a} 0 1 2 ---- [Additional list functions] | [Arts and crafts of Tcl-Tk programming] }