class Solution(object):
def topKFrequent(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
counts=dict()
res = []
lst = []
for n in nums:
counts[n] = counts.get(n,0)+1
for key, val in counts.items():
lst.append((val,key))
lst.sort(reverse=True)
for i in range(k):
res.append(lst[i][1])
return res