📌  相关文章
📜  计算字符串中字符的频率 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:39.462000             🧑  作者: Mango

代码示例1
#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