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

Steven D'Aprano steve at pearwood.info
Thu Feb 12 17:21:25 CET 2015


On Fri, Feb 13, 2015 at 02:46:45AM +1100, Chris Angelico wrote:

> Imagine if two people independently build shopping lists

Sorry, was that shopping *lists* or shopping *dicts*?

> - "this is the stuff we need" - and
> then combine them. You'd describe that as "your list and my list", or
> "your list plus my list" (but not "your list or my list"; English and
> maths tend to get "and" and "or" backward to each other in a lot of
> ways), and the resulting list would basically be set union of the
> originals. If you have room on one of them, you could go through the
> other and add all the entries that aren't already present; otherwise,
> you grab a fresh sheet of paper, and start merging the lists. (If
> you're smart, you'll group similar items together as you merge. That's
> where the analogy breaks down, though.) It makes fine sense to take
> two shopping lists and combine them into a new one, discarding any
> duplicates.

Why would you discard duplicates? If you need 2 loaves of bread, and I 
need 1 loaf of bread, and the merged shopping list has anything less 
than 3 loaves of bread, one of us is going to miss out.



-- 
Steve


More information about the Python-ideas mailing list