[ create a new paste ] login | about

Link: http://codepad.org/foNb9Pd3    [ raw code | output | fork ]

salai - Ruby, pasted on Oct 26:
1
2
3
4
5
6
7
8
9
10
11
12
class Hash
	def hash_revert
		hash_new = Hash.new
		self.each {|key,value|
			if not hash_new.has_key?(key) then hash_new[value] = key end
		}
		return hash_new
	end
end

h = {2=>"a", 1=> "b", 3 =>"a", 4=> "a", 5 => "b", 6=>"c"}
p h.hash_revert


Output:
1
{"a"=>4, "b"=>1, "c"=>6}


Create a new paste based on this one


Comments: