function call questions
MRAB
python at mrabarnett.plus.com
Tue Oct 18 23:46:12 EDT 2016
On 2016-10-19 03:15, chenyong20000 at gmail.com wrote:
> Thanks Peter and Anssi for your kind help. Now I'm ok with the first question. But the second question still confused me. Why "it seems that
> after root = root.setdefault(ch,{}) tree['a'] and root are the same
> object" and follows tree['a']['b']? Thanks.
>
You call the .setdefault method with a key and a default value.
The .setdefault method does this: if the key is in the dict, it returns
the associated value, else it puts the key and the default into the dict
and then returns the default.
More information about the Python-list
mailing list