I have an input file like this:
CCCCCCCCCCCCCBBBCCBBBBBBBBBBBCCCCCCCCCCCCCCCCBCCC
I want to count how many 'B' are there on each group. So the output will be:
B: 3, 11, 1
I tried two different scripts but both give the total number of B = 15.
Here is one of my attempts:
import collections
with open('input.txt') as infile:
counts = collections.Counter(B.strip() for B in infile)
for line, count in counts.most_common():
print line, count
Try this instead: