print("找出字符串中出现次数最多的字符,并输出其出现的位置")
str = "abbcccdddd"
第一种方法:
max = 0
i = 0
for a in str:
if max < str.count(a):
max = str.count(a)
while str.find(a,i) != -1:
i = str.find(a,i) + 1
print(i)
print(a)
第二种方法
str = "abbcccdddd"
word = ""
position = []
max = 0
dict_s = {}
for i in str:
if max > str.count(i):
max = str.count(i)
word = i
print(word)
for j in range(len(str)):
if str[j] == word:
position.append(j)
dict_s[word] = position
print(position)
print(dict_s)