The idea of the program is to count life time of some structures (count same structures which are one after another) but i have problem with implementing counter or enumerate function, I don't want to count number of all. I've tried do this many ways. Now I am stuck.
struct=[1, 2, 2, 2, 3, 3, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1,] #input list of structures
list1=[] #list of lifetimes for struct 1
for i in range (0, len(struct)-1):
a=struct[i-1]
b=struct[i]
c=struct[i+1]
if a!=1 and b==1 and c!=1: # if it is one separated record
list1.append(1)
if a!=1 and b==1 and c==1: # for first record in sequence
list1.append('f')
if a==1 and b==1 and c==1: # for middle record in sequence
list1.append('m')
if a==1 and b==1 and c!=1: # for last record in sequence
list1.append('l')
print (list1)
it gives me: [1, 1, 'f', 'm', 'm', 'l', 'f', 'l']
could you give me any advise how to implement counter ?
for example ['f', 'm', 'm', 'l] (firs/middle/middle/last) is given from [1, 1, 1, 1] from the list of structure so it's 4 records
to get [1, 1, 4, 2]
Sorry, for my non programming language, I am beginner in this field. I've search any similar questions but couldn't find.
for i in range (0, len(struct)-1):and beforeprint (list1)be indented?