Skip to content

Instantly share code, notes, and snippets.

@isidentical

isidentical/test_slices.py Secret

Created Nov 25, 2020
Embed
What would you like to do?
from collections import defaultdict
sequences = (
[1, 1, 0, 0, 0, 1, 1, 1],
[1, 0, 0, 0, 1, 1, 1, 1],
[1, 1, 0, 0, 0, 1, 1, 1],
[1, 0, 0, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 0, 0, 0],
[1, 1, 1, 1, 1, 0, 0, 0],
[1, 0, 0, 0, 1, 1, 1, 1],
[1, 1, 0, 0, 0, 1, 1, 1],
[1, 1, 0, 0, 0, 1, 1, 1],
)
def find_follow_ups(sequences):
follow_ups = defaultdict(list)
for sequence_id, sequence in enumerate(sequences):
for index, number in enumerate(sequence[:-2]):
if sequence[index:index+3] == [0, 0, 0]:
follow_ups[index:index+3].append(sequence_id)
return follow_ups
for slicer, sequence_ids in find_follow_ups(sequences).items():
for sequence_id in sequence_ids:
print(sequences[sequence_id][slicer])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment