3

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?

1 Answers1

6

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.

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323