hash of hashes

Tim Chase python.list at tim.thechases.com
Tue Jul 11 16:05:54 EDT 2006


> how do i create a hash of hash similar to perl using dict in python
> $x{$y}{z}=$z

Pretty much the same as in perl, only minus half the crazy abuses 
of the ASCII character-set.

Okay...well, not quite half the abuses in this case...

 >>> x = {}
 >>> y = 42
 >>> z = 'foonting turlingdromes'
 >>> x[y] = {}
 >>> x[y][z] = 'crinkly bindlewurdles'

Or, if you want to do it in a single pass:

 >>> x = {y:{z:'crinkly bindlewurdles'}}
 >>> x
{42: {'foonting turlingdromes': 'crinkly bindlewurdles'}}


-tkc







More information about the Python-list mailing list