From: Todd Benson Date: 2007-05-11T23:39:05+09:00 Subject: Re: how to remove dups from 2 lists? ------=_Part_62341_17590998.1178894343670 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline This is how I would do it (that is, if I understand the OP's request). a = %w( a a b b c e f) b = %w( b c c c d e e g) ha = {}; hb = {}; dif = {} ha.default = hb.default = 0 ca = []; cb = [] a.uniq.each { |i| a.each { |j| ha[i] += 1 if i == j } } b.uniq.each { |i| b.each { |j| hb[j| += 1 if i == j } } (ha.merge hb).keys.each { |k| dif[k] = ha[k] - hb[k] } dif.each { |k,v| v>0 ? ca += (k*v).split(//) : cb += (k*-v).split(//) } puts "list1: #{ (dif.each { |k,v| (k*v).split(//) if v>=0 }" # ["a", "a", "b", "f"] puts "list2: #{ (dif.each { |k,v| (k*-v).split(//) if v<0 }" # ["c", "c", "d", "e", "g"] Of course, you can only compare 2 lists. Todd ------=_Part_62341_17590998.1178894343670--