数据结构例题
from pprint import pprint
sentence = "This is a common interview question."
first = {}
for number in sentence:
if number in first:
first[number] += 1
else:
first[number] = 1
value = sorted(first.items(), key=lambda kv: kv[1], reverse=True)
print(value[0])
# 参考答案:
# from pprint import pprint
# sentence = "This is a common interview question."
# char_frequency = {}
# for char in sentence:
# if char in char_frequency:
# char_frequency[char] += 1
# else:
# char_frequency[char] = 1
# char_frequency_sorted = sorted(
# char_frequency.items(), key=lambda kv: kv[1],
# reverse=True
# )
# print(char_frequency_sorted[0])