# Top $k$ Frequent Elements
- leetcode.com/problems/top-k-frequent-elements/
## Solutions
- Use `Counter` to count frequency, then sort **based on value**.
```python
frequency = Counter(nums)
items_sorted = sorted(frequency.items(), key=lambda x:x[1], reverse=True)
return [item[0] for item in items_sorted[:k]]
```
Alternatively, use builtin method
```python
return [num for num, _ in counter.most_common(k)]
```