From 70b05d3305e7226db08d32d2c15052aa8b812838 Mon Sep 17 00:00:00 2001 From: Sai Sri Mourya Gudladona Date: Mon, 15 Oct 2018 23:14:21 -0400 Subject: [PATCH] Added more list operations (#18934) - Reverse a List - Splice a List --- .../pages/guide/english/python/lists/index.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/client/src/pages/guide/english/python/lists/index.md b/client/src/pages/guide/english/python/lists/index.md index 875e1f6071..0e56109b79 100644 --- a/client/src/pages/guide/english/python/lists/index.md +++ b/client/src/pages/guide/english/python/lists/index.md @@ -69,7 +69,22 @@ _Unpacking lists for python-3_ >>> print(*my_list) 1 2 9 16 25 ``` - +**Reverse a `list`:** +```shell +>>> my_list = [1, 2, 9, 16, 25] +>>> print(my_list[::-1]) +[25, 16, 9, 2, 1] +``` +**Slice a `list`:** +```shell +>>> my_list = [1, 2, 9, 16, 25] +>>> print(my_list[:-2]) #Access sub-elements first to length-2 +[1, 2, 9] +>>> print(my_list[2:]) #Access sub-elements 3rd to last element +[9, 16, 25] +>>> print(my_list[::2]) #Access list by skipping 2 indexes +[1, 9, 25] +``` **Mutable:** `lists` are mutable containers. Mutable containers are containers that allow changes to which objects are contained by the container. **TODO: ADD MORE?**