We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Top k most frequent words
1 parent 26815ce commit b71e97aCopy full SHA for b71e97a
strings/top_k_frequent_words.py
@@ -1,5 +1,16 @@
1
"""
2
Finds the top K most frequent words from the provided word list.
3
+
4
+This implementation aims to show how to solve the problem using the Heap class
5
+already present in this repository.
6
+Computing order statistics is, in fact, a typical usage of heaps.
7
8
+This is mostly shown for educational purposes, since the problem can be solved
9
+in a few lines using collections.Counter from the Python standard library:
10
11
+from collections import Counter
12
+def top_k_frequent_words(words, k_value):
13
+ return [x[0] for x in Counter(words).most_common(k_value)]
14
15
16
0 commit comments