# Minor question about optimally increasing last item of a list

What is the best way to increase the last item of a list by one? I've come up with ++list[[Length[list]]], is there something more efficient?

• :) ++list[[-1]] closely related: 42455
– Kuba
Dec 7 '15 at 19:07
• @Kuba Thanks! Now that I know I also know I should figure out myself :D Dec 7 '15 at 20:00

In my timings with a=Range[100000]

++a[[-1]]

a[[-1]] += 1

a[[-1]] = a[[-1]] + 1


and

++a[[100000]]

a[[100000]] += 1

a[[100000]] = a[[100000]] + 1


all evaluate in the same time.

• How about a[[Length[a]]] with nobody-knows-how-long a? Dec 7 '15 at 21:18
• It takes fractionally longer. Dec 7 '15 at 21:24