Open this example in the interactive library
Source code
segments = [[]]
for event in ['up', 'go', '|', 'stop', '|', 'end']:
if event == '|':
segments.append([])
else:
segments[-1].append(event)
print(segments)
Sample output
[['up', 'go'], ['stop'], ['end']]
