Created
September 10, 2019 09:54
-
-
Save miodeqqq/80d48d892ac755a423e95049e20f9693 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
class ArticleHashtags: | |
def __init__(self, text): | |
self.text = text | |
def get_most_common_words(self, n=5, text_min_lenth=5): | |
""" | |
Returns 5 most common words in string. | |
""" | |
words = list( | |
filter( | |
None, | |
[x.strip().lower().strip(',"') for x in self.text.split() if len(x) >= text_min_lenth if x] | |
) | |
) | |
most_common_words = dict(Counter(words).most_common(n)) | |
return list(map(lambda x: '#' + x, most_common_words)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment