Skip to content

Instantly share code, notes, and snippets.

@djipko
Created February 10, 2012 22:22
Show Gist options
  • Save djipko/1793551 to your computer and use it in GitHub Desktop.
Save djipko/1793551 to your computer and use it in GitHub Desktop.
Embedly solution #3
from operator import add
if __name__ == "__main__":
most_frequent = 2520
freq_list = [most_frequent/n for n in xrange(1, 901)]
total_w = reduce(add, freq_list)
half = total_w/2
cnt = 0
for i, f in enumerate(freq_list, start = 1):
cnt+=f
if cnt > half:
print "The first %d most frequent words make up half the text" %(i+1)
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment