When I read a file, it gives me an output like this:
CW 0.000000 0.003822 0.006380 0.005100 0.016987 0.307042
CW 0.007136 0.019635 0.329683 0.315180 0.302634 0.007076
CW 0.015666 0.299244 0.290860 0.292623 0.325943 0.005236
CS 0.022060 0.288761 0.311449 0.289165 0.289937 0.317213
CS 0.019635 0.040511 0.301167 0.011418 0.295902 0.017166
CS 0.020990 0.345277 0.352370 0.034237 0.020962 0.015749
I want to count the total number of CW and CS in the file. The output should look like this:
3 #For CW
3 #For CS
I tried using the following code:
with open ("file", 'r') as rf:
v=rf.read().split('\n')
i=[]
for e in v[1::47]: #(only the names)
r=(e[:12])
s=(r[:2])
q= sum(c != ' ' for c in s)
print(q)
But it gives me this output
2
2
2
2
2
2
I even tried importing counter, but it gives me output like this:
C 1
W 1
C 1
W 1
C 1
S 1
Please suggest some method so that I can get the expected output. Any help will be highly appreciated.