#encoding=utf-8
"""
找出s=”aabbccddxxxxffff”中,出现次数最多的字母
"""
#方法1有缺陷:最大数相同的,只能你输出最后一个
#自定义一个最大数数,然后统计每个字母出现的次数,和最大数字对比
def find_Most_Occurrence_Letter(s):
most_occurrence_num=0
target_Letters=""
for i in s:
if s.count(i)>=most_occurrence_num:
most_occurrence_num=s.count(i)
target_Letters=i
return target_Letters,most_occurrence_num
s="aabbccddxxxxffff"
print(find_Most_Occurrence_Letter(s))
#方法2:用字典保存字母和对应的重复个数,找出最大值然后从字典中输出
def find_Most_Occurrence_Letter1(s):
target_dict={}
for i in s:
target_dict[i]=s.count(i)
max_Letter=max(target_dict.values())
for k,v in target_dict.items():
if max_Letter==v:
print(k)
s="aabbccddxxxxffff"
print(find_Most_Occurrence_Letter1(s))