Skip to content

Instantly share code, notes, and snippets.

@romainmet
romainmet / word_frequencies_top.txt
Last active December 19, 2021 02:10
Udacity Assessment Answer - Machine Learning Nanodegree
"""Count words."""
count={}
def count_words(s, n):
"""Return the n most frequently occuring words in s."""
wordlist = s.split()
wordfreq = [wordlist.count(p) for p in wordlist]
zip_l=dict(zip(wordlist,wordfreq))
sort=sorted(zip_l.iteritems(),key=lambda(k,v):(-v,k))