F
Fredrik Lundh
No doubt you're right but common sense dictates that membership testing
would test identity not equality.
what does "common sense" have to say about this case:
# True or False ?
</F>
No doubt you're right but common sense dictates that membership testing
would test identity not equality.
I understand this, Steve.
I thought the _cmp_ method was a helper for sorting purposes. Why is it
that a membership test needs to call the __cmp__ method?
>>> a = {1:'one'}
>>> b = {2:'two'}
>>> c = {1:'one'}
>>> a is c False
>>> a in [b, c] True
>>>
If this isn't a bug, it is at least unexpected in my eyes.
Maybe a candidate for inclusion in the FAQ?
Thank you for answering
Steve said:Consider:>>> a = {1:'one'}
>>> b = {2:'two'}
>>> c = {1:'one'}
>>> a is c False
>>> a in [b, c] True
>>>
What would you have Python do differently in these circumstances?
Steve Holden wrote:
Consider:
a = {1:'one'}
b = {2:'two'}
c = {1:'one'}
a is c False
a in [b, c] True
What would you have Python do differently in these circumstances?
You mean: What i would do i if i was the benevolent dictator ?
I would make a distinction between mutables and immutables. Immutables
would test for equality and mutables would test for identity.
It's not worth bothering - just work with Python how it is, and enjoyMembership testing for objects is a very common use case which is
totally unrelated to their being sorted according to a key.
I am no expert on languages so i could be wrong. Don't hesitate to
correct me.
Alain
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.