Skip to content

Instantly share code, notes, and snippets.

@jaysonrowe
Created July 29, 2012 21:55
Show Gist options
  • Save jaysonrowe/3202064 to your computer and use it in GitHub Desktop.
Save jaysonrowe/3202064 to your computer and use it in GitHub Desktop.
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