python - Searching for an isolated list element -


i need find index of element in list not part of specific sublist.

here example:

list = [0,0,0,1,1,1,1,0,0,0,1,0,0] 

i have function determine if list sublist of larger list, don't know how use in context, since isolated 1 @ beginning or @ end of list. there 4 consecutive 1s , 1 isolated 1.

input list 4 consecutive 1s , 1 isolated 1. other elements 0.

the output should location(index) of isolated element, in example 10.

you can loop through each element between 1 , length of list - 2 , both inclusive, , print element surrounded 0s , , before loop check if start elemnt , whether 1 , second element 0 , or end element whether 1 , second last element 0 .

code -

if lst[0] == 1 , lst[1] == 0:     return 0 if lst[len(lst)-1] == 1 , lst[len(lst)-2] == 0:     return 1 in range(1,len(lst)-1):     if lst[i] == 1 , lst[i-1] == 0 , lst[i+1] == 0:         return 

use xrange better memory usage in python 2.x


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -