Message241320
https://docs.python.org/3/reference/expressions.html#comparisons:
----------------------------------------------------------------
The operators 'in' and 'not in' test for membership. 'x in s' evaluates to true if x is a member of s, and false otherwise. 'x not in s' returns the negation of 'x in s'. All built-in sequences and set types support this as well as dictionary, for which 'in' tests whether the dictionary has a given key. For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expression 'x in y' is equivalent to 'any(x is e or x == e for e in y)'.
StackOverflow question for context: http://stackoverflow.com/q/29692140/208880
Summary: if a user creates a broken object such that __hash__ returns a random number with every invocation, then that object will get lost in a dict or set; but the above statement about 'equivalent to' claims that such an object will still be found.
On the other hand, https://docs.python.org/3/glossary.html#term-hashable says that a constant return value is required for an object to be hashable (of course, Python can't tell if future calls to __hash__ will return the same value).
Perhaps a link to the #term-hashable would be appropriate? |
|
Date |
User |
Action |
Args |
2015-04-17 08:09:25 | ethan.furman | set | recipients:
+ ethan.furman, georg.brandl, ezio.melotti, eric.araujo |
2015-04-17 08:09:25 | ethan.furman | set | messageid: <1429258165.63.0.284734084008.issue23987@psf.upfronthosting.co.za> |
2015-04-17 08:09:25 | ethan.furman | link | issue23987 messages |
2015-04-17 08:09:25 | ethan.furman | create | |
|