On 2007-06-28, Alan Isaac <[EMAIL PROTECTED]> wrote: > A.T.Hofkamp wrote: > >>>>>a = Car2(123) >>>>>b = Car2(123) >>>>>a == b >> >> True >> >>>>>set([a,b]) >> >> set([Car2(123), Car2(123)]) >> >> I get a set with two equal cars, something that never happens with a set >> my math teacher once told me. > > > Then your math teacher misspoke. > You have two different cars in the set, > just as expected. Use `is`. > http://docs.python.org/ref/comparisons.html > > This is good behavior.
Hmm, maybe numbers in sets are broken then? >>> a = 12345 >>> b = 12345 >>> a == b True >>> a is b False >>> set([a,b]) set([12345]) Numbers and my Car2 objects behave the same w.r.t. '==' and 'is', yet I get a set with 1 number, and a set with 2 cars. Something is wrong here imho. The point I intended to make was that having a default __hash__ method on objects give weird results that not everybody may be aware of. In addition, to get useful behavior of objects in sets one should override __hash__ anyway, so what is the point of having a default object.__hash__ ? The "one should override __hash__ anyway" argument is being discussed in my previous post. Albert -- http://mail.python.org/mailman/listinfo/python-list