Skip to content

Instantly share code, notes, and snippets.

@ooade
Created November 22, 2017 06:51
Show Gist options
  • Save ooade/3e63d190fee7a1e25e12424afeb0a808 to your computer and use it in GitHub Desktop.
Save ooade/3e63d190fee7a1e25e12424afeb0a808 to your computer and use it in GitHub Desktop.
Udacity ML
def count_words(w, n):
words = []
s = list(set(w.split()))
s.sort()
for word in s:
words.append((word, w.split().count(word)))
words.sort(key = lambda x: (x[1]), reverse = True)
return words[:n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment