Skip to content

Instantly share code, notes, and snippets.

@cmeury
Last active March 31, 2016 15:47
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 cmeury/63a85865147d090fef695fa533a0bae7 to your computer and use it in GitHub Desktop.
Save cmeury/63a85865147d090fef695fa533a0bae7 to your computer and use it in GitHub Desktop.
# Data:
list = [-1, 1, 2, 3, -1, 4, 5, 6, -1]
# == Determine bondaries ===
minus = []
# iterate over list
for l in range(len(list)):
if list[l] == -1:
minus.append(l)
# add a dividing point to end if no -1 present
if list[len(list)-1] != -1:
minus.append(len(list))
# == Exract segments ===
segments = []
# set boundary manually to one earlier if we're not starting with a -1
if list[0] != -1:
last = -1
last = 0
for m in minus:
if not last == m:
segments.append(list[last:m])
last = m + 1
for segment in segments:
print(segment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment