Modifying the {} and [] tokens

Mel Wilson mwilson at the-wire.com
Sun Aug 31 11:28:40 EDT 2003


In article <e6bfkvsnro96db74j8en20tuqm0tml23lr at 4ax.com>,
Geoff Howland <ghowland at lupineNO.SPAMgames.com> wrote:
>On Sat, 23 Aug 2003 13:39:15 -0400, "Terry Reedy" <tjreedy at udel.edu>
>wrote:
>>With respect to {}+{}.  An in-place version of this is currently
>>spelled {}.update({}).  Yes, more chars to type, but also more
>>'honest' in not implying symmetry between the two dicts.  As the name
>>suggests, duplicate key with new value overrides previous value.
>
>What's really the problem with a + sugar though?  Currently there is
>no sugar, and update() really all there is to it.

   There's no single clear idea on how that sugar should
taste, particularly when the operands have keys in common.

   Personally, the applications I've written so far would
like dictionary addition d+u to work like

        for k in u.keys():
            d[k] = d.get (k, additive_identity) + u[k]

where additive_identity is a magical value that's 0 working
with numbers, [] with lists, () with tuples and '' with
strings.  In real life I'd catch the key errors instead.

   But those are yesterdays programs.  If you asked me to
guarantee that tomorrows program would use this, I'd refuse.

        Regards.        Mel.




More information about the Python-list mailing list