Python Quiz
Grant Edwards
grante at visi.com
Thu Jul 17 15:31:20 EDT 2003
In article <X7ydnRCQKq4rdIuiXTWJjQ at comcast.com>, Terry Reedy wrote:
>> Yup. I found a lot of things in FORTRAN surprising. Python is
>> so much nicer in that respect. Though I was recently surprised
>> that the remove() method for lists uses "==" and not "is" to
>> determine what to remove. It's documented that it works that
>> way. But, it wasn't what I excpected, and it took me a while to
>> figure out that it was using my class's __cmp__ method rather
>> than the object ID.
>
> Given ints = [9, 99, 999, 9999] would it not surprise you even more if
> ints.remove(99) worked and ints.remove(999) did not, or even worse, if
> the behavior of ints.remove(99) depended on the implementation?
Yes, it would.
> (Similar examples apply to strings, where the implementation of
> interning and hence behavior based on identity *has* changed!)
I'm not claiming it's right, or even rational, but for
user-defined objects, I expected it to use "is". Now I know
better, and am more careful when I impliment __cmp__. I had
expected to be able to have two different objects that compared
equal. And I also expected to be able to use list.remove() to
remove a specified object. I had to give up one or the other.
--
Grant Edwards grante Yow! ... he dominates the
at DECADENT SUBWAY SCENE.
visi.com
More information about the Python-list
mailing list