Skip to content

Instantly share code, notes, and snippets.

@fbehrens
Created February 4, 2010 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbehrens/295236 to your computer and use it in GitHub Desktop.
Save fbehrens/295236 to your computer and use it in GitHub Desktop.
data = <<-HERE
chile,santiago,5000000,02
chile,valparaiso,100000,55
chile,la serena,80000,56
usa,los angeles,15000000,44
usa,washington dc,500000,88
china,beijing,14000000,98
HERE
result = Hash.new{|h,k| h[k] = [] }
data.each do |line|
country , *p = line.chomp.split(",")
result[ country ] << p
end
puts result.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment