Last active
March 31, 2016 15:47
-
-
Save cmeury/63a85865147d090fef695fa533a0bae7 to your computer and use it in GitHub Desktop.
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
# 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