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

Joshua Landau joshua.landau.ws at gmail.com
Fri Jul 5 23:38:22 CEST 2013


On 5 July 2013 10:48, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
> I didn't know about the str.partition method but having looked at it
> now what it does is closer to what I think of as a partition of a set
> i.e. after
>
>     head, sep, tail = str1.partition(str2)
>
> we have that
>
>     str1 == head + sep + tail
>
> By analogy I would expect that after
>
>     set2, set3, set4 = set1.partition(...)
>
> we would have
>
>     set1 == set2 | set3 | set4
>
> because that is (one property of) a "partition" of set1. However this
> is not the meaning you intend.

Hence why it should be defined:

    set1.partition(set2) === set1 - set2, set1 & set 2

That lets you have the "single pass" of each set as before, but is a
"smaller" operation. The full partition would just plot "set2 - set1"
on the end:

ven_a, ven_shared = a.partition(b)
ven_b = ven_b - ven_shared

And "ven_a | ven_shared == a" as you said.


More information about the Python-ideas mailing list