On 6 July 2013 05:56, Paddy3118 <paddy3118@gmail.com> wrote:
On Friday, 5 July 2013 22:38:22 UTC+1, Joshua Landau wrote:
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.
Unfortunately I tend to need all three of exclusively1, common, exclusively2 . Assuming fast C implementations, then your proposal would lead to less opportunity for optimization and the need to create one needed result in Python. The need for all three and the potentially better optimization afforded to computing three at once in C should outweigh any considerations of the name of the method.
I don't believe it would be any (measurably) slower, given the single-pass optimisations shown in other posts. I could be wrong, but it's not like Python's known for it's micro-optimisations (except for dicts...). I also think that my way is better *because* of efficiency concerns -- if it's not measurably slower for the 3-way split, surely it's more useful to allow people to have a fast 2-way split. It's also a simpler, less redundant implementation. I could give you some uses of my partition over 3-way partitioning: flags = set(...) flags_passed_to_next_in_chain, flags_kept = flags.partition(flags_that_I_want) The rest are all variations of this.