---------- Forwarded message (apologies, the CC says it all) ---------- From: Joshua Landau firstname.lastname@example.org Date: 4 July 2013 00:57 Subject: Re: [Python-ideas] exclusively1, common, exclusively2 = set1 - set2, set1 & set2, set2 - set1 To: Paddy3118 email@example.com Cc: firstname.lastname@example.org
On 3 July 2013 21:50, Paddy3118 email@example.com 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
- What passed first time round
- What passed both times.
- 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.
As far as I understand, this requires only 3 traversals in total.
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?
You could cut it down to two, AFAIK. This seems like a minor gain.
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)
Something more useful, as it's just as good in this case could be:
set1.partition(set2) === set1 - set2, set1 & set 2
similarly to how we have divmod.