Re: How to say $a=$b->{"A"} ||={} in Python?
- From: James Stroud <jstroud@xxxxxxxxxxxx>
- Date: Thu, 16 Aug 2007 16:21:00 -0700
beginner 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"} ||={}.
I'm afraid you've asked a non sequiter:
euler 40% cat test.pl
$a=$b->{"A"} ||={} ;
print "$a\n" ;
$b->{"B"} = 0 ;
$a=$b->{"B"} ||={} ;
print "$a\n" ;
$b->{"X"} = 15 ;
$a=$b->{"X"} ||={} ;
print "$a\n" ;
euler 41% perl test.pl
HASH(0x92662a0)
HASH(0x926609c)
15
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
.
- Follow-Ups:
- Re: How to say $a=$b->{"A"} ||={} in Python?
- From: beginner
- 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: Pass by reference or by value?
- Next by Date: Re: Cancelling events on a COM Object
- 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):