From: Trans Date: 2005-08-01T04:01:06+09:00 Subject: Re: QUESTION: Good data structure for list within list with duplicates? The appropriate structure is probably Associative Arrays in Hash. { "x" => [ [ "aa", 2 ], [ "aa", 3 ], [ "bb", "boo" ], ... ], "y" => [ [ "aa", 5 ], [ "cc" , "see" ], [ "cc" , "sea" ], ... ], ... } You can create you own class for it too, start with something like this: class PairHash def initialize() @outer = Hash.new([]) end def add_entry( x, y, z ) a = [y,z] @outer[x] << a a end def del_entry( x, y=nil ) if y @outer[x].reject! { |e| e[0] == y } else @outer.delete(x) end end def inner_value?( v, x, y ) @outer[x].select { |e| e == [y,v] } end end # demo ph = PariHash.new ph.add_entry( "x", "aa", 2 ) ph.add_entry( "x", "aa", 3 ) ph.add_entry( "x", "bb", "boo" ) ph.inner_value?( 3, "x", "aa" ) ) T.