You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

From: akuchlin at (Andrew M. Kuchling)
Date: Wed, 28 Apr 1999 11:11:07 -0400 (EDT)
Subject: try vs. has_key()
In-Reply-To: <>
References: <>
Message-ID: <>
X-UID: 94
William H. Duquette writes:
>>>> d = {}
>>>> a = 'Foo'
>>>> d[a] = d.get(a, []).append('Bar')
>>>> d
>{'Foo': None}
>I'd have expected to see {'Foo': 'Bar'}, but that's not what I get.
The .append() method only returns None, not the list you've
just appended to.
>>> L = []
>>> print L.append(2)
>>> L
You'd want something like:
dummy = d[a] = d.get(a, [])
A.M. Kuchling
When I originally designed Perl 5's OO, I thought about a lot of this stuff,
and chose the explicit object model of Python as being the least confusing. So
far I haven't seen a good reason to change my mind on that.
-- Larry Wall, 27 Feb 1997 on perl5-porters