How to count letter frequencies in a string with Python

1 Answer

0 votes
s = "python java php cpp"

frequencies = {}
for ch in s:
    frequencies[ch] = frequencies.get(ch, 0) + 1

for item in frequencies.items():
    print(item)
    
    
    
'''
run:

('p', 5)
('y', 1)
('t', 1)
('h', 2)
('o', 1)
('n', 1)
(' ', 3)
('j', 1)
('a', 2)
('v', 1)
('c', 1)

'''

 



answered Oct 22, 2020 by avibootz
...