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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -