summaryrefslogtreecommitdiffhomepage
path: root/python.html.markdown
diff options
context:
space:
mode:
authorMark Whiting <mark.whiting@gmail.com>2014-02-17 21:07:29 -0500
committerMark Whiting <mark.whiting@gmail.com>2014-02-17 21:07:29 -0500
commitda3b7c3520b18bf5b94d99bcf8170d679051810a (patch)
treebec313b2e7907f3b378b93af456e9e328dc5e229 /python.html.markdown
parent5ff5f6c0d864f6ec300f14e49119d4e259dbf4be (diff)
Better explanation of list slices
Step size and list slice syntax was not quite clear. Upon seeing li[::-1] as it was previously, I was not sure what this really meant so I looked it up and found that this section of the guide may benefit from more explanation.
Diffstat (limited to 'python.html.markdown')
-rw-r--r--python.html.markdown4
1 files changed, 4 insertions, 0 deletions
diff --git a/python.html.markdown b/python.html.markdown
index 15f27d37..908a0638 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -160,8 +160,12 @@ li[1:3] #=> [2, 4]
li[2:] #=> [4, 3]
# Omit the end
li[:3] #=> [1, 2, 4]
+# Select every second entry
+li[::2] #=>[1,4]
# Revert the list
li[::-1] #=> [3, 4, 2, 1]
+# Use any combination of these to make advanced slices
+# li[start:end:step]
# Remove arbitrary elements from a list with "del"
del li[2] # li is now [1, 2, 3]