User | Kudos |
---|---|
10 | |
6 | |
6 | |
5 | |
4 |
I think it would save a bit of space, and time, if we could use a negative array index value in order to quickly get the last element of an array. This would also work for 2nd to last item, 3rd to last, etc.
When I started working with Python I thought it was rather useful and intuitive to be able to quickly reference the last item in an array in that way. Like so:
>>> a= [1, 2, 3]
>>> print a[-3]
1
>>> print a[-2]
2
>>> print a[-1]
3
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.