Python输入一个字符串,统计每个字符出现的次数,并找出出现次数最多的字符
时间: 2024-04-30 14:17:59 浏览: 105
Python 经典算法100及解析(小结)
好的,可以使用Python中的字典来实现,代码如下:
```python
string = input("请输入一个字符串:")
count_dict = {}
for char in string:
if char in count_dict:
count_dict[char] += 1
else:
count_dict[char] = 1
max_count = max(count_dict.values())
max_char = []
for key, value in count_dict.items():
if value == max_count:
max_char.append(key)
print("每个字符出现的次数:", count_dict)
print("出现次数最多的字符:", max_char)
```
输入一个字符串后,程序会输出每个字符出现的次数以及出现次数最多的字符。
阅读全文