Created
November 22, 2017 06:51
-
-
Save ooade/3e63d190fee7a1e25e12424afeb0a808 to your computer and use it in GitHub Desktop.
Udacity ML
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
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