count letter from txt file in python -


this question has answer here:

files contain below letter. a- c f c c b- b a a- b b+ b+ b+ c c- b- a f. need read file , below output.

6 students got 2 students got a- 3 students got b+ 

and on, far able go through file not able count sting, can 1 please guide me.

infile = open('grades.txt')   content = infile.read()  char in content:     print (char, end=' ') 

i output below

a - c f c c b - b - b b + b + b + c c - b - f

can please guide me how can count occurance.

thanks.

since looks homework problem i'll give hint.

c=counter("a a- c f c c b- b a a- b b+ b+ b+ c c- b- a f".split()) c.most_common() [('a', 6), ('c', 4), ('b+', 3), ('b', 2), ('f', 2), ('b-', 2), ('a-', 2), ('c-', 1)] 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -