# Data chapter

proc ldelete { list value } {
	set ix [lsearch -exact $list $value]
	if {$ix >= 0} {
		return [lreplace $list $ix $ix]
	} else {
		return $list
	}
}

proc mycompare {a b} {
	set alast [lindex $a [expr [llength $a]-1]]
	set blast [lindex $b [expr [llength $b]-1]]
	set res [string compare $alast $blast]
	if {$res != 0} {
		return $res
	} else {
		return [string compare $a $b]
	}
}
set list {{Brent B. Welch} {John Ousterhout} {Miles Davis}}
lsort -command mycompare $list
