[Python-ideas] Adding "+" and "+=" operators to dict
Stephen J. Turnbull
stephen at xemacs.org
Thu Feb 12 18:52:18 CET 2015
Chris Angelico writes:
> I live in a house with a lot of people.
I live in a rabbit hutch that can barely hold 3 people, let alone a
week's groceries. So do most of the natives here.
So when you go to Costco and buy eggs by the gross and pork by the
kilo, you take a bunch of friends, and add your shopping dicts
keywise. Then you take all the loot to somebody's place, and split up
the orders in Tupperware and collect the money, have some green tea,
and then everybody goes home.
The proposal to have dicts add keywise has actually been made on this
list, and IIRC the last time is when collections.Counter was born.
I'm a definite -1 on "+" or "|" for dicts. "+=" or "|=" I can live
with as alternative spellings for "update", but they're both pretty
bad, "+" because addition is way too overloaded (even in the shopping
list context) and I'd probably think it means different things in
different contexts, and "|" because the wrong operand wins in
"short-circuit" evaluation.
More information about the Python-ideas
mailing list