Multidimensional Dictionaries: Possible?

Chris Withers chrisw at nipltd.com
Tue Jan 25 12:40:56 EST 2000


> > Here's how I do it in Perl:
> > %dict = ();  # create empty dictionary
> > $dict{$key1}{$key2} = $string;       # make an entry
> > $newstring = ${dict{$key1}{$key2}};  # access an entry
> 
> dict = {}
> dict[key1, key2] = string
> newstring = dict[key1, key2]

What's the quickest way to do the equivalent of the following Perl in Python,
again, using the above example:

$dict{$key1}{$key2}++

I can only think of the following, I hope there is a better way! :

a =  dict[key1, key2]
a = a + 1
dict[key1, key2] = a

cheers,

Chris



More information about the Python-list mailing list