Created
April 8, 2015 16:17
-
-
Save sk187/42f639e685ab25834498 to your computer and use it in GitHub Desktop.
Python List Slicing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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