-1

I have a list

series = [0 1 1 0 1 0 1 0 0 0 1 .....]

I wish to find the indices where two 1's are separated by 2 indices ex. [0 1 0 1] now the location is 1 and 3. Now I wish to do the same for bigger list.

Matlab code for this purpose is

find(conv(series,[1 0 1])==2) 
Ullas
  • 3
  • 4
  • Does this answer your question? https://stackoverflow.com/questions/36620085/find-the-position-of-sublist-in-a-list-in-python – jrmylow Sep 28 '20 at 14:01

1 Answers1

1

see below.

is that what you are looking for?

s = [0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1]
data = []
for x in range(0,len(s)-1):
    if x > 0:
        if s[x-1] == 1 and s[x] != 1 and s[x+1] == 1:
            data.append(x)
print(data)

output

[3, 5]
balderman
  • 22,927
  • 7
  • 34
  • 52