Skip to content

Instantly share code, notes, and snippets.

@uncompiled
Last active September 2, 2017 21:11
Show Gist options
  • Save uncompiled/b12cb46bda57ea817800a9248dcea6ff to your computer and use it in GitHub Desktop.
Save uncompiled/b12cb46bda57ea817800a9248dcea6ff to your computer and use it in GitHub Desktop.
Array Splicing in Python
# 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