Created
July 29, 2012 21:55
-
-
Save jaysonrowe/3202064 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
h = Hash.new | |
f = File.open('numbers.csv', "r") | |
f.each_line { |line| | |
numbers = line.split | |
numbers.each { |w| | |
if h.has_key?(w) | |
h[w] = h[w] + 1 | |
else | |
h[w] = 1 | |
end | |
} | |
} | |
# sort the hash by value, and then print it in this sorted order | |
h.sort{|a,b| a[1]<=>b[1]}.each { |elem| | |
puts "\"#{elem[0]}\" has #{elem[1]} occurrences" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment