How to say $a=$b->{"A"} ||={} in Python?
Jonathan Gardner
jgardner.jonathangardner.net at gmail.com
Thu Aug 16 21:28:34 EDT 2007
On Aug 16, 3:35 pm, beginner <zyzhu2... at gmail.com> wrote:
>
> In perl it is just one line: $a=$b->{"A"} ||={}.
>
a = b.setdefault('A', {})
This combines all two actions together:
- Sets b['A'] to {} if it is not already defined
- Assigns b['A'] to a
More info on dict methods here:
http://docs.python.org/lib/typesmapping.html
More information about the Python-list
mailing list