Skip to content

Instantly share code, notes, and snippets.

@bchase
Last active August 29, 2015 14:01
Show Gist options
  • Save bchase/f2900cefc755b89c79af to your computer and use it in GitHub Desktop.
Save bchase/f2900cefc755b89c79af to your computer and use it in GitHub Desktop.
# the hash
hash = Hash.new {|h,k| h[k] = 0}
# populate the hash
File.open('email').each do |line|
line.split(/\s+/).each do |word|
hash[word] += 1
end
end
# print, most occurrences first
hash.sort_by{|str,count| count}.reverse.each do |arr|
str, count = *arr
puts "#{str}: #{count}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment