Feedback on Sets, and Partitions

A. Lloyd Flanagan alloydflanagan at comcast.net
Fri Apr 30 09:40:17 EDT 2004


"Steve" <humean at fea.st> wrote in message news:<mailman.136.1083282936.25742.python-list at python.org>...
> Another unintutive feature is that there can be multiple sets with the
> same members. I.e., you can have sets A and B such that "A == B" is true
> and "A is B" is false. I would like more information on the reasons for
> this choice and whether there would be anything to gain or lose by having
> "A == B" entail "A is B".
> 

I can't speak for the designers, but I think there's two problems with
A == B => A is B.  One, none of the other sequences behave that way. 
Two (and this is the real killer) I think it would be tough to
implement.
A = Set([1, 2, 3])
B = Set([1, 2])
#A is B clearly false, as is A==B
B.add(3)
#Now A==B is true

After every alteration of a set, such as the add() above, you'd have
to do an exhaustive comparison of every other set for equality.  Then
you'd do something like B = A to drop the old B set and set up another
reference to A.  Then if you altered B and not A, you'd have to do
something like copy A, make the change, and assign the result to B.

Problem with that is, it breaks the case where you want A and B to be
pointing to a single set which is modified so that A and B change. 
The most common case would be passing a Set to a subroutine.

So I just don't think it's feasible.



More information about the Python-list mailing list