Skip to content

Instantly share code, notes, and snippets.

@sk187
Created April 8, 2015 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sk187/42f639e685ab25834498 to your computer and use it in GitHub Desktop.
Save sk187/42f639e685ab25834498 to your computer and use it in GitHub Desktop.
Python List Slicing
# Python list can be manipulated as follows:
my_list = [1,2,3,4,5,6,7,8,9,10]
# my_list[start_index : end_index : stride]
# Default for start index is 0
# Default for end index is the end of the list
even_num_list = my_list[1::2]
# Returns
[2, 4, 6, 8, 10]
odd_num_list = my_list[::2]
# Returns
[1, 3, 5, 7, 9]
reverse_list = my_list[::-1]
# Returns
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment