How to make tree of dictionaries?
Vlad Sirenko
zcoder at bigmir.net
Wed Aug 13 19:13:12 EDT 2003
>>>>> "Michael" == Michael Peuser writes:
>> ($month,$date,$hour,$minute,$sec,$year) = ($1,$2,$3,$4,$5,$6);
>> $statistics->{$year}->{$month}->{$date} += $sec;
Michael> This is what I love Perl for! BTW: Do you really mean += ? This
Michael> does nor match yourt example, neither seems to make much
Michael> sense. Perhaps a misconception?
It doesn't matter. I just wanted to express the main idea and you caught it
everything else has minor meaning.
>> tmp_year = stats.setdefault(year, {})
>> tmp_month = tmp_year.setdefault(month, {})
>> tmp_month[date] = tmp_month.setdefault(date, 0) + sec
Michael> *I* think this is less readable than the Python expression!
Did you mean Perl expression? If so, may be it's time for another language
change?
Michael> Note that *get* and *setdefault* are most powerful operations on
Michael> mapping types once you get used to them, that is... ;)
Mapping types give great power and flexibility when programmer need to
describe and manage structured data.
--
WBR, VS
The world is coming to an end ... SAVE YOUR BUFFERS!!!
More information about the Python-list
mailing list