3.14 PAT1042 乙级 python

字符统计

import re
pat = '[a-zA-Z]+'
l = re.findall(pat,input())
l = ''.join(l).lower()
l = list(l)
l.sort()
lst = []
count = []
for i in l:
	if i in lst:
		count[lst.index(i)] += 1
	else:
		lst.append(i)
		count.append(1)
print(lst[count.index(max(count))]+' '+str(max(count)))

猜你喜欢

转载自blog.csdn.net/qq_39782006/article/details/88558777