From: akuchlin at cnri.reston.va.us (Andrew M. Kuchling) Date: Wed, 28 Apr 1999 11:11:07 -0400 (EDT) Subject: try vs. has_key() In-Reply-To: <37247ea3.494305@news.jpl.nasa.gov> References: <37247ea3.494305@news.jpl.nasa.gov> Message-ID: <14119.9202.870049.51888@amarok.cnri.reston.va.us> 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) None >>> L [2] You'd want something like: dummy = d[a] = d.get(a, []) dummy.append('Bar') -- A.M. Kuchling http://starship.python.net/crew/amk/ 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