Rotate left n
elements (or right for negative n):
L = L[n:] + L[:n]
Note that collections.deque has support for rotations. It might be better to use that instead of lists.
More Related Contents:
- Python swapping and slicing method
- How does assignment work with list slices?
- Select rows in pandas MultiIndex DataFrame
- Slicing a list in Python without generating a copy
- What is the difference between slice assignment that slices the whole list and direct assignment?
- Implementing slicing in __getitem__
- Pandas – Slice large dataframe into chunks
- Can I create a “view” on a Python list?
- What is :: (double colon) in Python when subscripting sequences?
- Python pandas slice dataframe by multiple index ranges
- How to get last items of a list in Python?
- Understanding string reversal via slicing
- Extract elements of list at odd positions
- What does [:] mean?
- Slicing of a NumPy 2d array, or how do I extract an mxm submatrix from an nxn array (n>m)?
- How to query MultiIndex index columns values in pandas
- Python Array Slice With Comma?
- Selecting Random Windows from Multidimensional Numpy Array Rows
- Reversing a list using slice notation
- Python reverse-stride slicing
- Insert element in Python list after every nth element
- Iteration over list slices
- Why python’s list slicing doesn’t produce index out of bound error? [duplicate]
- How to slice a generator object or iterator?
- How to explain the reverse of a sequence by slice notation a[::-1]
- What are the default slice indices *really*?
- How to slice a pandas DataFrame by position?
- How can I slice each element of a numpy array of strings?
- Slicing multiple ranges of columns in Pandas, by list of names
- Fast Way to slice image into overlapping patches and merge patches to image