Slice notation in short:
[ <first element to include> : <first element to exclude> : <step> ]
If you want to include the first element when reversing a list, leave the middle element empty, like this:
foo[::-1]
You can also find some good information about Python slices in general here:
Explain Python’s slice notation
Related Contents:
- How does assignment work with list slices?
- Slicing a list in Python without generating a copy
- What is the difference between slice assignment that slices the whole list and direct assignment?
- Pairs from single list
- Can I create a “view” on a Python list?
- How to get last items of a list in Python?
- Slicing a list into n nearly-equal-length partitions [duplicate]
- Extract elements of list at odd positions
- Python Array Slice With Comma?
- Reversing a list using slice notation
- Insert element in Python list after every nth element
- Understanding slicing
- How do you split a list into evenly sized chunks?
- Modifying list while iterating [duplicate]
- How do I check if a list is empty?
- What are the advantages of NumPy over regular Python lists?
- How do I initialize a dictionary of empty lists in Python?
- Get unique values from a list in python [duplicate]
- How to extract the n-th elements from a list of tuples
- Python: Finding differences between elements of a list
- Why does Python skip elements when I modify a list while iterating over it?
- Finding the average of a list
- How to read a text file into a list or an array with Python
- Python recursion with list returns None [duplicate]
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- How to remove \n from a list element?
- Calling filter returns [duplicate]
- How can I make a dictionary from separate lists of keys and values?
- Why is [] faster than list()?
- elegant find sub-list in list
- How to group a list of tuples/objects by similar index/attribute in python?
- Looping over a list in Python [closed]
- Understanding string reversal via slicing
- Why does appending to one list also append to all other lists in my list of lists? [duplicate]
- Finding elements not in a list
- merging Python dictionaries
- Move an item inside a list?
- How do I convert a list into a string with spaces in Python?
- Remove dictionary from list
- Is it possible to get a list of keywords in Python?
- What are the default slice indices *really*?
- Modifying a list while iterating over it – why not? [duplicate]
- Python: filter list of list with another list
- How to get the Cartesian product of multiple lists
- Identify groups of consecutive numbers in a list
- Given parallel lists, how can I sort one while permuting (rearranging) the other in the same way?
- List as a member of a python class, why is its contents being shared across all instances of the class?
- Find min, max, and average of a list
- Why does list ask about __len__?
- Column of lists, convert list to string as a new column