DarkSand
DarkSand

Reputation: 23

How do I find the largest index in a list

how do i print the highest index number?

Upvotes: 0

Views: 146

Answers (1)

Schelte Bron
Schelte Bron

Reputation: 4813

The highest index is just one less than the length of the list. So:

puts [expr {[llength $list] - 1}]

To print the element at the largest index, you can refer to it as 'end':

puts [lindex $list end]

If I misunderstood the question and you want the index of the largest number in the list, that can be done as follows:

puts [lindex [lsort -indices -integer -decreasing $list] 0]

Upvotes: 2

Related Questions