[Python-ideas] Adding "+" and "+=" operators to dict

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Feb 13 23:12:10 CET 2015


Stefan Behnel wrote:
> Arithmetic expressions are always
> evaluated from left to right. It thus seems obvious to me what gets created
> first, and what gets added afterwards (and overwrites what's there).

I'm okay with "added afterwards", but the "overwrites"
part is *not* obvious to me.

Suppose you're given two shopping lists with instructions
to get everything that's on either list, but not double
up on anything. You don't have a spare piece of paper
to make a merged list, so you do it this way: Go through
the first list and get everything on it, then go
through the second list and get everything on that.

Now one list contains "Bread (preferably white)" and
the other contains "Bread (preferably wholemeal)".
You haven't been told what to do in case of a conflict,
it's left to your judgement.

What do you when you encounter the second entry for
bread? Do you put the one you have back and grab the
other one, or do you just think "I've already got
bread" and move on? Which is more obvious?

-- 
Greg


More information about the Python-ideas mailing list