Python语言基础-2.8字符串基本操作-第3关:统计字频
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 7 15:23:19 2020
@author: hyr
拼接,统计字数,将空格改为换行,查找子串,
"""
songs=input()#仅包含空格和中文字
################begin#############
#1. 输出songs中出现最多的一个中文字,并输出该字出现次数。
#注意:如果有多个字出现次数相同,请以原文本中最先出现的那个为准。
#创建空字典
dic={}
#删去空格
songsnsp=songs.replace(' ','')
for word in songsnsp:
#判断字典中是否存在该键
if word in dic.keys():
dic[word]+=1
else:
dic[word]=1
pyout=max(dic,key=dic.get)
pot=dic[pyout]
print(pyout,pot)
################end#############