Re: How to say $a=$b->{"A"} ||={} in Python?
- From: Carl Banks <pavlovevidence@xxxxxxxxx>
- Date: Thu, 16 Aug 2007 16:03:40 -0700
On Aug 16, 6:35 pm, beginner <zyzhu2...@xxxxxxxxx> wrote:
Hi All.
I'd like to do the following in more succint code:
if k in b:
a=b[k]
else:
a={}
b[k]=a
a['A']=1
In perl it is just one line: $a=$b->{"A"} ||={}.
Thanks,
Geoffrey
Define b as a default dict:
b = defaultdict(dict)
b[k]['A'] = l
Carl Banks
.
- Follow-Ups:
- Re: How to say $a=$b->{"A"} ||={} in Python?
- From: Paul McGuire
- Re: How to say $a=$b->{"A"} ||={} in Python?
- References:
- How to say $a=$b->{"A"} ||={} in Python?
- From: beginner
- How to say $a=$b->{"A"} ||={} in Python?
- Prev by Date: Re: How to say $a=$b->{"A"} ||={} in Python?
- Next by Date: Re: Pass by reference or by value?
- Previous by thread: Re: How to say $a=$b->{"A"} ||={} in Python?
- Next by thread: Re: How to say $a=$b->{"A"} ||={} in Python?
- Index(es):