def char_frequency(string):
# Create an empty dictionary to store the frequency of each character
frequency = {}
for char in string:
# If the character is already in the dictionary, increment its count
if char in frequency:
frequency[char] += 1
# If the character is not in the dictionary, add it with a count of 1
else:
frequency[char] = 1
return frequency
string = "Python is a general-purpose programming language"
result = char_frequency(string);
for key, value in result.items():
print(key, value)
'''
run:
P 1
y 1
t 1
h 1
o 3
n 4
5
i 2
s 2
a 5
g 5
e 4
r 4
l 2
- 1
p 3
u 2
m 2
'''