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

Paddy3118 paddy3118 at gmail.com
Sat Jul 6 18:46:30 CEST 2013


On Wednesday, 3 July 2013 21:50:35 UTC+1, Paddy3118 wrote:
>
> I found myself repeating something that I know I have used before, several 
> times: I get two sets of results, may be sets of the passing tests when a 
> design has changed, and I need to work out what has changed so work out 
>
> 1. What passed first time round
> 2. What passed both times.
> 3. What passed only the second time round.
>
> I usually use something like the set equations in the title to do this but 
> I recognise that this requires both sets to be traversed at least three 
> times which seems wasteful.
>
> I wondered if their was am algorithm to partition the two sets of data 
> into three as above, but cutting down on the number of set traversals?
>
> I also wondered that if such an algorithm existed, would it be useful 
> enough to be worth incorporating into the Python library? 
>
> Maybe defined as:
>
> exclusively1, common, exclusively2 = set1.partition(set2)
>


   - Others who have used this construct have now come to light which was 
   one of my goals.
   - There is an algorithm  that can save on the set traversals and that 
   might be quicker when implemented in C - another of my goals.
   
We are currently arguing on the name which I must admit does need to be 
agreed, but usually takes a disproportionate amount of time to agree. 
(Especially when we all think that of course my solution is obviously the 
best ;-)

I re-read the Wikipedia article on Venn diagrams as I am indeed asking for 
a split of two sets into the regions depicted in a two variable Venn 
diagram. The punny name *vennerate *gains some credibility, but that awful 
pun just has to die a quick death. *vennsplit*, *venndiv*, *vennpartition*, 
*vpartition *are new name candidates on the same theme but without the pun. 

The division Of two two sets that I am asking for is related to truth tables

set1 set2 : Resultant
==== ==== : =========
  0    0  : Items not in set1 and not in set2; - Dumb!
  1    0  : Items     in set1 and not in set2; exclusively1
  0    1  : Items not in set1 and     in set2; exclusively2
  1    1  : Items not in set1 and not in set2; common

The above leads to a generalization for more than two sets; for example 
three sets and a change in nomenclature for the resultants would lead to:

(bin001, bin010, bin011, bin100, 
 bin101, bin110, bin111) = set0.partition(set1, set2)

...But three sets and more should be abandoned I think as being too 
complicated for little gain.



 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130706/9d9375c8/attachment.html>


More information about the Python-ideas mailing list