Is there a way to access the last element of a List
using a special index like in python where -1 return the last element? avoiding to write extra code like list.size - 1
.
An example of the python way here.
I've tried following but doesn't work:
fun main() {
val numbers = (1..5).toList()
println(numbers[-1])
}
Any help or explanation will be appreciated.