[Tutor] creating dict of dict : similar to perl hash of hash
Alan Gauld
alan.gauld at btinternet.com
Tue Mar 6 19:25:27 CET 2012
On 06/03/12 17:50, Abhishek Pratap wrote:
> I am looking for a way to build dictionaries of dict in python.
Thats not a problem, you just nest them:
d1 = {key: value,...} # a single level dictionary
d2 = {key: d1, ...} # a dictionary of dictionaries...
d3 = { key1: {key2: value, ...}, ...} # and on one line
> 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.
No idea, I haven't done any Perl for over 10 years.
What does that actually do?
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list