Andrew Koenig wrote:
Why can't you do this? foo = log.setdefault(r,'') foo += "test %d\n" % t
You can do it, but it's useless!
d = {} foo = d.setdefault(42, "buckle") foo += " my shoe" d {42: 'buckle'}
What Mr. Leighton wanted is *impossible* when the value concerned is immutable, because by the time you get to the += operator, there's no information left about where the value came from, and thus no way to update the dict with the new value. Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+