python - Count the number of lines after each pattern -


i have file lines, lines have particular pattern. number of lines after each pattern differs , want count number of lines after each pattern.

<pattern> line 1 line 2 line 3 <pattern> line 1 line 2 etc 

my code:

for line in fp:    c = 0    if line.startswith("<"):         header = line.split(" ")    else:         c = c+1 

the code have captures pattern lines, don't know how stop before next pattern , start count after pattern.

just save c array , set c = 0

a array l length of array

array a; l = 0; line in fp:  c = 0  if line.startswith("<"):     header = line.split(" ")     a[l] = c     c = 0     l = l+1  else:     c = c+1 

to read values can read array 0 l:

for in range(0,l):   print "c%d %d" % (i,a[i]) 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -