python内置方法可以同时根据key和val排序
学会一招
def topKFrequent(self, words, k):
"""
:type words: List[str]
:type k: int
:rtype: List[str]
"""
res = Counter(words)
res = sorted(res.items(),key = lambda x : (-x[1],x[0]))
return [c for c,v in res][:k]