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

Carsten Haese carsten at uniqsys.com
Fri Aug 17 00:02:11 EDT 2007


On Fri, 17 Aug 2007 03:15:10 -0000, beginner wrote
> On Aug 16, 9:32 pm, Carsten Haese <cars... at uniqsys.com> wrote:
> > 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).

If you have to look up all values associates with k1 and any k2, you're right,
that's not efficient. That would fall under "other constraints you're not
telling us." I'm not a mind reader.

-Carsten




More information about the Python-list mailing list