[Tutor] creating dict of dict : similar to perl hash of hash

Joel Goldstick joel.goldstick at gmail.com
Tue Mar 6 19:19:51 CET 2012


On Tue, Mar 6, 2012 at 12:50 PM, Abhishek Pratap <abhishek.vit at gmail.com> wrote:
> Hi Guys
>
> I am looking for a way to build dictionaries of dict in python.
>
> For example in perl I could do
>
> my $hash_ref = {};
> $hash->{$a}->{$b}->{$c} = "value";
> if (exists $hash->{$a}->{$b}->{$c} ){ print "found value"}
>
> Can I do something similar with dictionaries in Python.
>
>
> Thanks
> -Abhi
>
>
Dictionaries can contain dictionaries in python:

>>> sub_d = {'key1':'value1'}
>>> d = {'subd1':sub_d}
>>> d
{'subd1': {'key1': 'value1'}}
>>> d['subd1']
{'key1': 'value1'}
>>>

The Python site has information  here:
http://docs.python.org/tutorial/datastructures.html#dictionaries

>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick


More information about the Tutor mailing list