S
spar
I'm converting a Perl script to Python and have run into something I'm
not sure how to do in Python.
In Perl, I am running through a couple loops and inserting values
directly into a complex data structure (array->hash->array). This
isn't the actual code, but should demonstrate the general idea:
foreach $bar_count(@bars) {
foreach $el_count(@els) {
$var = somefunc($bar_count,$el_count);
$data[$bar_count]->{'CC'}->[$el_count] = $var;
}
}
Basically I'd like to do the same thing in Python. I've written a
convoluted test script where I can print an element:
print data[0]['CC'][1]
but I can't insert directly like I do in Perl (data[0]['CC'][1] =
$var). In my test script I've simply initialized my lists and
dictionary at the beginning of the script, not by iterating an
inserting values as in the Perl example.
Any advice appreciated...thanks.
not sure how to do in Python.
In Perl, I am running through a couple loops and inserting values
directly into a complex data structure (array->hash->array). This
isn't the actual code, but should demonstrate the general idea:
foreach $bar_count(@bars) {
foreach $el_count(@els) {
$var = somefunc($bar_count,$el_count);
$data[$bar_count]->{'CC'}->[$el_count] = $var;
}
}
Basically I'd like to do the same thing in Python. I've written a
convoluted test script where I can print an element:
print data[0]['CC'][1]
but I can't insert directly like I do in Perl (data[0]['CC'][1] =
$var). In my test script I've simply initialized my lists and
dictionary at the beginning of the script, not by iterating an
inserting values as in the Perl example.
Any advice appreciated...thanks.