mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
14 lines
301 B
Python
14 lines
301 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
def top_k_frequent_values(list, k):
|
|
|
|
if k == len(nums):
|
|
return nums
|
|
|
|
# hashmap element: frequency
|
|
counter = Counter(nums)
|
|
return heapq.nlargest(k, counter.keys(), key=counter.get)
|