On Aug 16, 9:32 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-08-17 at 00:53 +0000, beginner wrote: > > $b is supposed to be a hash-table of hash-table. If a key exists in > > $b, it points to another hash table. The $a=$b->{"A"} ||={} pattern is > > useful when you want to add records to the double hash table. > > > For example, if you have a series of records in the format of (K1, K2, > > V), and you want to add them to the double hash-table, you can do > > $a=$b->{K1} || ={} > > $a->{K2}=V > > What is the best solution in Perl need not be the best solution in > Python. In Python you should just use a tuple as your dict key, i.e. > a[k1,k2] = v, unless you have some other constraints you're not telling > us. > > HTH, > > -- > Carsten Haesehttp://informixdb.sourceforge.net
I use tuples this way all the time. It is indeed very neat. But it is not a replacement for double hash-table. If I want to retrieve information just by K1, it is not efficient to index on (K1, K2). -- http://mail.python.org/mailman/listinfo/python-list