0

Being a Perl convert I'm wondering, if it is possible in Python to create more then one level of keys in a dictionary.

In Perl, if I have an empty hash, I can e.g. write this:

my %h;  # emtpy hash
$h{level1}{level2}{level3} = "something";

Do I really have to do the same thing in Python like this:

h = {}   # empty dictionary
h['level1'] = {}
h['level1']['level2'] = {}
h['level1']['level2']['level3'] = "something"

or is there a shortcut?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
petro4213
  • 163
  • 9

0 Answers0