Skip to content

Commit b71e97a

Browse files
committed
Mentioning Python standard library solution in Top k most frequent words docstring
1 parent 26815ce commit b71e97a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: strings/top_k_frequent_words.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
"""
22
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)]
314
"""
415

516

0 commit comments

Comments
 (0)