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

MRAB python at mrabarnett.plus.com
Thu Jul 4 02:15:32 CEST 2013


On 03/07/2013 21:50, 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)
>
How common is this need? I suspect that it's not that common.

As to "seems wasteful", is it a performance bottleneck? I also suspect
not (you even say "seems"! :-)).



More information about the Python-ideas mailing list