From: Erik Veenstra Date: 2007-01-25T20:48:33+09:00 Subject: Re: can it be shorter? There's a glitch, which is not yet mentioned... Consider this old hash: {["A", "B"]=>"C", ["B", "A"]=>"D"} What's the value of new_hash["A"]? Is it "C", or is it "D"? That depends on the order on which you build the new hash. Which depends on the order in which you walk through the old hash. Which isn't deterministic, AFAIK. Maybe it is determinstic if you know in which order the old hash was built. But, given _a_ hash, you simply don't know the order in which you walk through it, so you don't know the order in which the new hash will be built, so you don't know what the result is going to be. Cool... Adding a sort to the algorithm fixes this. gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- hash.collect do |k,v| [[k].flatten, v] end.sort.inject({}) do |h,(ks,v)| ks.each do |k| h[k] = v end h end ----------------------------------------------------------------