I'm trying to find out how many times a certain element is non-consecutively appearing in a list.
By that I mean:
list = [10,10,10,11,12,10,12,14,10,10,10]
element_searched = 10
=> expected_output = 3
So that means that 10 is appearing 3 times in a the list.
My code so far that seems to be working:
elements = [11, 10, 12]
row = [10,10,10,10,10,10,10,10,10,11,11,11,11,11,10,10,10,10,12,12,12,12,12,11,11,11,11,12,12,12,12,10]
element_on = False
for element in elements:
sequence = 0
for i in range(len(row)):
if element == row[i] and element_on==False:
sequence += 1
element_on = True
elif element==row[i] and element_on==True:
pass
elif element != row[i] and element_on==True:
element_on = False
elif element != row[i] and element_on == False:
element_on = False
print(f"For element {element} the number ob sequences is: {sequence} ")
I am getting the desired output but I am wondering if there is a more elegant and especially a faster way.