Negative numbers mean that you count from the right instead of the left. So, list[-1]
refers to the last element, list[-2]
is the second-last, and so on.
More Related Contents:
- How to add numbers inside a variable? [closed]
- Python – get unique and sorted values in list of lists [closed]
- Remove all the elements that occur in one list from another
- Copying nested lists in Python
- Finding the average of a list
- How to switch position of two items in a Python list?
- Case insensitive ‘in’
- Changing an element in one list changes multiple lists [duplicate]
- Alphabet range in Python
- Python list confusion [duplicate]
- Joining pairs of elements of a list [duplicate]
- I want to exception handle ‘list index out of range.’
- Convert string to list. Python [string.split() acting weird]
- How do you split reading a large csv file into evenly-sized chunks in Python?
- How to convert nested list of lists into a list of tuples in python 3.3?
- Numpy individual element access slower than for lists
- list.extend and list comprehension [duplicate]
- Pairwise crossproduct in Python [duplicate]
- How to allow list append() method to return the new list
- Pythonic Circular List
- What’s the difference between plus and append in python for list manipulation? [duplicate]
- Assign multiple values of a list
- TypeError: list indices must be integers or slices, not list
- Deleting consonants from a string in Python
- Convert a number to a list of integers [duplicate]
- If in Python I put a list inside a tuple, can I safely change the contents of that list? [duplicate]
- How to find the maximum number in a list using a loop?
- Given a list of elements in lexicographical order (i.e. [‘a’, ‘b’, ‘c’, ‘d’]), find the nth permutation – Average time to solve?
- Join a list of strings in python and wrap each string in quotation marks
- count occurrence of a list in a list of lists