How to say $a=$b->{"A"} ||={} in Python?

Carsten Haese carsten at uniqsys.com
Thu Aug 16 22:32:19 EDT 2007


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 Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list