1吗讶、不考慮去重
#不考慮去重
s = "xssdddeeeeffff"
max_times = 0
result = {}
for i in s:
if s.count(i) > max_times:
result.clear()
result[i] = s.count(i)
max_times = s.count(i)
elif s.count(i) == max_times:
result[i] = s.count(i)
print (result)
2躺率、考慮去重
str = 'a1fsfs111bbbcccccvvvvvnnnnboooooosssnb'
class Countvalue():
def countvalue(self, str1):
'''
利用set自身的去重功能
:param str1: 對傳進(jìn)來的字符串過濾
:return: 返回一個不含重復(fù)字符的list
'''
list1 = []
result = []
for x in str1:
list1.append(x)
result = set(list1)
return result
def count(self, str1):
'''
對已經(jīng)去重的list進(jìn)行遍歷,因已去重
從而減少循環(huán)次數(shù)棵逊,提高檢索效率
:param str1:
:return:
'''
list = Countvalue().countvalue(str1)
a = 0
tump = {}
for x in list:
test = str1.count(x)
if test > a:
tump.clear()
a = test
tump[x] = a
elif test == a:
a = test
tump[x] = a
return tump
if __name__ == '__main__':
print(Countvalue().count(str))