Skip to content

Instantly share code, notes, and snippets.

@klahrich
Created April 10, 2020 17:24
Show Gist options
  • Save klahrich/1f2d356bfecdd58c23beb6ff4fdbea8c to your computer and use it in GitHub Desktop.
Save klahrich/1f2d356bfecdd58c23beb6ff4fdbea8c to your computer and use it in GitHub Desktop.
# Challenge no 1: you have a list of sentences. What are the top-3 most frequent words (case-insensitive) longer than 3 characters.
from collections import Counter
sentences = ["This is the first sentence", "My first time was in Havana", "What is it this time", "Time is precious"]
words = [word.lower() for sentence in sentences for word in sentence.split()]
counter = Counter([word for word in words if len(word) >= 3])
counter.most_common(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment