programming-examples/python/Basics/Python program to count the number of characters (character frequency) in a string.py

10 lines
249 B
Python
Raw Normal View History

2019-11-18 14:44:36 +01:00
def char_frequency(str1):
dict = {}
for n in str1:
keys = dict.keys()
if n in keys:
dict[n] += 1
else:
dict[n] = 1
return dict
print(char_frequency('google.com'))