#version 1 import re from collections import Counter
defget_max_value_v1(text): text = text.lower() result = re.findall('[a-zA-Z]', text) # 去掉列表中的符号符 count = Counter(result) # Counter({'l': 3, 'o': 2, 'd': 1, 'h': 1, 'r': 1, 'e': 1, 'w': 1}) count_list = list(count.values()) max_value = max(count_list) max_list = [] for k, v in count.items(): if v == max_value: max_list.append(k) max_list = sorted(max_list) return max_list[0]
1 2 3 4 5 6 7
#version 2 from collections import Counter
defget_max_value(text): count = Counter([x for x in text.lower() if x.isalpha()]) m = max(count.values()) returnsorted([x for (x, y) in count.items() if y == m])[0]
1 2 3 4 5 6
#version 3 import string
defget_max_value(text): text = text.lower() returnmax(string.ascii_lowercase, key=text.count)
Checking if Disqus is accessible...