[Tutor] Test Question

Hugo Arts hugo.yoshi at gmail.com
Mon Jul 1 13:21:29 CEST 2013


On Mon, Jul 1, 2013 at 1:01 PM, Dave Angel <davea at davea.name> wrote:

> On 07/01/2013 05:58 AM, John Steedman wrote:
>
>>
>> I believe that "my_sequence" might be a either container class or a
>> sequence type. An effective __hash__ function would be required for each
>> "my_object".
>>
>
> "in" doesn't care if there's a __hash__ function.  It just cares if the
> collection has a __contains__() method.  If the collection is a dict, the
> dict will enforce whatever constraints it needs.  If the collection is a
> list, no has is needed, but the __contains__() method will probably be
> slower.  In an arbitrary sequence it won't have a __contains__() method,
> and I believe 'in' will iterate.
>
>
It will indeed iterate. It's always useful to check the language reference
in cases like these to see precise behaviour:
http://docs.python.org/2/reference/expressions.html#membership-test-details

Hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130701/3b0d0ff0/attachment.html>


More information about the Tutor mailing list