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?
Asked
Active
Viewed 112 times
3
მამუკა ჯიბლაძე
- 2,066
- 14
- 27
1 Answers
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
++list[[-1]]closely related: 42455 – Kuba Dec 07 '15 at 19:07