题目:https://www.hackerrank.com/challenges/most-commons/problem
题意:按照次数升序,次数相同降序
思路:s = sorted(Counter(input()).items(), key= lambda x: (-x[1],x[0]))[:3]
详细可见python dict sorted 排序
代码:
'''
-*- coding: utf-8 -*-
@Author : PlayerGuan
@Time : 2017/10/14 23:12
@Software: PyCharm Community Edition
@File : main.py
'''
from collections import Counter
s = sorted(Counter(input()).items(), key= lambda x: (-x[1],x[0]))[:3]
for x in s:
print(x[0]+" "+str(x[1]))