Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Content(models.Model):
- description = models.TextField()
- author = models.ForeignKey(Author, on_delete=models.CASCADE)
- def __str__(self):
- return self.description
- def get_most_used_words(self, count):
- words = {}
- stop_words = set(stopwords.words('english'))
- description = self.description.split()
- for element in description:
- if element not in stop_words:
- if element in words:
- words[element] += 1
- else:
- words[element] = 1
- top_10_words = sorted(words.items(), key=lambda x: -x[1])[:count]
- return top_10_words
Advertisement
Add Comment
Please, Sign In to add comment