Word frequency: Difference between revisions

no edit summary
No edit summary
Line 3,696:
that->7924
it->6661
</pre>
===Chain of Enumerables===
<lang ruby>wf = File.read("135-0.txt", :encoding => "UTF-8")
.downcase
.scan(/\w+/)
.each_with_object(Hash.new(0)) { |word, hash| hash[word] += 1 }
.sort_by { |k, v| v }
.reverse
.take(10)
.each_with_index { |w, i|
printf "[%2d] %10s : %d\n",
i += 1,
w[0],
w[1]
}
</lang>
{{out}}
<pre>[ 1] the : 41040
[ 2] of : 19951
[ 3] and : 14942
[ 4] a : 14539
[ 5] to : 13941
[ 6] in : 11209
[ 7] he : 9646
[ 8] was : 8620
[ 9] that : 7922
[10] it : 6659
</pre>
 
Anonymous user