Skip to content

Instantly share code, notes, and snippets.

@sceeter89
Created September 23, 2015 18:43
Show Gist options
  • Save sceeter89/385e367726d737fef7b7 to your computer and use it in GitHub Desktop.
Save sceeter89/385e367726d737fef7b7 to your computer and use it in GitHub Desktop.
Lin: Reorder array
import collections
input_array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
output_array = []
temp = collections.deque(input_array)
from_beginning = True
while temp:
output_array.append(temp.popleft() if from_beginning else temp.pop())
from_beginning = not from_beginning
print(output_array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment