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

Eric V. Smith eric at trueblade.com
Mon Jul 8 10:24:39 CEST 2013


On 7/8/2013 3:22 AM, Steven D'Aprano wrote:
> On Sun, Jul 07, 2013 at 02:37:56PM -0700, David Mertz wrote:
>> On Jul 7, 2013 2:09 PM, "Eric V. Smith" <eric at trueblade.com> wrote:
>>>
>>> On 7/7/2013 1:45 AM, David Mertz wrote:
>>>> Maybe the generalization isn't worthwhile.  I was thinking that maybe a
>>>> more general version should keep order in types that have order to start
>>>> with, so I confess I'm not certain what the "correct" interface would
>> be.
>>>>
>>>> But even if it were only for sets, I like the idea of a plain function
>>>> much better than a method of a set, even if the only arguments it
>>>> accepted were sets.
>>>
>>> If it were added, I think a classmember on set would be reasonable.
>>
>> I agree.
> 
> A class member? Do you mean a class *method*?

I did mean classmethod, thanks. Or maybe staticmethod, I haven't really
thought it through. The point being, it need not be an instance method.

> I think it would be freaky and weird if I did this:
> 
> some_set.venn_split(second_set, another_set)
> 
> (for lack of a better name) and the value of some_set was ignored. Class 
> methods are okay for things like alternate constructors, but I don't 
> think they are appropriate here.

set.venn_split(second_set, another_set)

It's no more surprising than this code not using the values from d:

>>> d = {'a':1, 'b':2}
>>> d.fromkeys([3, 4, 5])
{3: None, 4: None, 5: None}

versus:

>>> dict.fromkeys([3, 4, 5])
{3: None, 4: None, 5: None}

-- 
Eric.


More information about the Python-ideas mailing list