今天爱分享给大家带来统计一段字符串中字符出现的次数【面试题详解】,希望能够帮助到大家。
def count_str(str_data):
"""定义一个字符出现次数的函数"""
dict_str = {}
for i in str_data:
dict_str[i] = dict_str.get(i,0)+1
return dict_str
dict_str = count_str("AAABBCCAC")
str_count_data = ""
for k,v in dict_str.items():
str_count_data += k +str(v)
print(str_count_data)
原文链接:http://blog.itblood.com/4191.html,转载请注明出处。

![合欢宗女修传 V0.175 官方中文[电脑/354M] [国风仙侠RPG/像素动态/官中]](/wp-content/uploads/replace/2025/09/15/a3c3606e1cb08cf4c48abda04bc1c968.webp)