Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement