Created
February 24, 2015 10:51
-
-
Save lostseaway/8c92d235b7d14a27d83f to your computer and use it in GitHub Desktop.
This file contains 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
f = File.open("AliceInWonderland.txt", "r") | |
a = "" | |
f.each_line do |line| | |
a +=line | |
end | |
f.close | |
a = a.gsub(".","").gsub("!","").gsub(",","").gsub(";","").gsub("\"","").gsub("(","").gsub(")","").gsub("?","").gsub(":","").split(" ") | |
m = {} | |
a.map{|x| | |
if m[x] == nil | |
m[x]=1 | |
else | |
m[x]+=1 | |
end | |
} | |
m = m.sort_by{|_key, value| _key.downcase} | |
m = m[0..19] | |
m.each{|x| puts x[0]+" : "+x[1].to_s} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment