[Python-ideas] exclusively1, common, exclusively2 = set1 - set2, set1 & set2, set2 - set1

Stephen J. Turnbull stephen at xemacs.org
Sat Jul 6 17:34:51 CEST 2013


Steven D'Aprano writes:

 > "partition" is not the ideal name for this method,

+1

It would completely confuse anybody who did want a partition.

 > but the actual operation itself is very useful. I have often done
 > this, mostly on dict views rather than sets. In my head, it's an
 > obvious operation, to split a pair of sets into three, spoiled only
 > by lack of a good name.
 > 
 > Perhaps "split" is a reasonable name?
 > 
 > only1, both, only2 = set1.split(set2)

-1

Set splitting is an intractable problem.
https://en.wikipedia.org/wiki/Set_splitting_problem

That wouldn't bother me all that much except that I can imagine all
kinds of ways to split sets that have little to do with boolean
algebra (starting with Dedekind cuts, you see how messy this will
get).  This particular operation is quite a ways down my list of
candidates.

I propose "join".[1]

If we consider set1 and set2 as implicitly defining the partition of
some universe into set1 and complement of set1, and respectively the
partition of the same universe into set2 and its complement, then what
you have here is the lattice-theoretic join of the two partitions (the
coarsest common refinement), with (as before) "everything else in the
universe" being implied (ie, left out of the result).  This also
generalizes well to more than two sets.

I suspect that anybody who wants a true partition join will define a
partition class, and will define their own join.  So this slight abuse
of terminology probably won't cause that much trouble.

Footnotes: 
[1]  Or maybe it's the meet?  I never can keep the two straight....



More information about the Python-ideas mailing list