On Mon, Jul 1, 2013 at 1:01 PM, Dave Angel <da...@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
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor