complex data structure - insert value

Alex Martelli aleaxit at yahoo.com
Mon Oct 11 09:24:44 CEST 2004


spar <spariam at hotmail.com> wrote:
   ...
> foreach $bar_count(@bars) {
>   foreach $el_count(@els) {
>     $var = somefunc($bar_count,$el_count);
>     $data[$bar_count]->{'CC'}->[$el_count] = $var;
>   }
> }

Not quite sure what you mean, but maybe s/thing like...:

data = {}

for bar_count in bars:
    for el_count in els:
        var = somefunc(bar_count, el_count)
        subdict = data.set_default(bar_count, {})
        subdict = subdict.set_default('CC', {})
        subdict[el_count] = var

...?


Alex



More information about the Python-list mailing list