Last active
September 2, 2017 21:11
-
-
Save uncompiled/b12cb46bda57ea817800a9248dcea6ff to your computer and use it in GitHub Desktop.
Array Splicing in Python
This file contains hidden or 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
# Here's a list of 5 people. | |
example_array = ["Alice", "Bob", "Jess", "Lisa", "Susan"] | |
middle = len(example_array) // 2 | |
# This is shorthand for saying: "Give me the first half of the array" | |
# This is equivalent to example_array[0:middle] | |
first_half = example_array[:middle] | |
# ['Alice', 'Bob'] | |
# This is shorthand for saying: "Give me the second half of the array" | |
# This is equivalent to example_array[middle:len(example_array)] | |
second_half = example_array[middle:] | |
# ['Jess', 'Lisa', 'Susan'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment