V
Vlad Sirenko
I need:
dict = {2002 : {'Jan': {1 : 'num1', 2: 'num2', 3 : 'num3'},
{'Feb': {1 : 'num4', 2: 'num5', 3 : 'num6'} } }
2003 : {'Jan': {1 : 'num7', 2: 'num8', 3 : 'num9'} } }
How to do it programmatically?
In Perl I would do something like:
while ($line = <>) {
if ($line =~ /^---\s+\w+\s+(\w+)\s+(\d*)\s+(\d+)
\d+)
\d+)\s+(\d+)\s+---$/) {
($month,$date,$hour,$minute,$sec,$year) = ($1,$2,$3,$4,$5,$6);
$statistics->{$year}->{$month}->{$date} += $sec;
}
}
But how to do it in Python without catching 'KeyError' exception or
iterating over some nested loops. How to do it elegantly?
dict = {2002 : {'Jan': {1 : 'num1', 2: 'num2', 3 : 'num3'},
{'Feb': {1 : 'num4', 2: 'num5', 3 : 'num6'} } }
2003 : {'Jan': {1 : 'num7', 2: 'num8', 3 : 'num9'} } }
How to do it programmatically?
In Perl I would do something like:
while ($line = <>) {
if ($line =~ /^---\s+\w+\s+(\w+)\s+(\d*)\s+(\d+)
($month,$date,$hour,$minute,$sec,$year) = ($1,$2,$3,$4,$5,$6);
$statistics->{$year}->{$month}->{$date} += $sec;
}
}
But how to do it in Python without catching 'KeyError' exception or
iterating over some nested loops. How to do it elegantly?