📅  最后修改于: 2022-03-11 14:45:39.462000             🧑  作者: Mango
#count the frequency of a character in a string using a dictionary
s=input("enter string: ")
a={}
for i in s:
if i not in a:
a[i]=s.count(i)
else:
pass
print("frequency")
for ch in a:
print(ch,a[ch])
#output
enter string: hello world
frequency
h 1
e 1
l 3
o 2
1
w 1
r 1
d 1